Web3Kitas a Dependency
To use the
Web3Kit library in a Swift Package Manager (SPM) project, add the following line to the dependencies in you
.package(url: "https://github.com/KevinVitale/Web3Kit", from: "0.0.2"),
Web3Kit library is under active development, and while attempts are made to maintain source-stability, this is not guaranteed between minor versions. You may specify
.upToNextMinor(from:), instead of
from(_:), if you need to be at a specific version.
Web3Kit clients can work with any node source, such as:
All this makes testing on macOS, iOS, or Linux really simple.
An architectural goal for
Web3Kit is to be small, yet flexible and expressive.
For any request you want to make, call
(request:parameters:) with a string literal:
// Create a client let web3 = Web3Client("127.0.0.1:8545") // Calls 'web3_sha3' let result = try await web3(request: "sha3", parameters: ["0xdeadbeef"]).result print(result ?? "")
For convenience, most requests have statically defined equivalents. For the above example:
// Create a client let web3 = Web3Client("127.0.0.1:8545") // Calls 'web3_sha3' let result = try await web3(request: .sha(data: "0xdeadbeef")).result print(result ?? "")
This example checks the balances of all the accounts on the node. It also demonstrates how
my micro-framework, Wei can be used to convert
// Create a client let web3 = Web3Client("127.0.0.1:8545") // Use `.eth' to invoke domain-specific API requests let balance = web3.eth(request: "getBalance", parameters: ["0x0000000000000000000000000000000000000000"]).result ?? "" // Print the amount in ETHER print(balance(as: .wei).to(.ether))
Web3Kit is part of a suite of Ethereum tools and frameworks built for those who ❤️ Swift.
|Last commit: 1 week ago|
Waring: breaking changes abound.