web3swift is an iOS toolbelt for interaction with the Ethereum network.
Join our discord or Telegram if you need support or want to contribute to web3swift development!
geth
compatible)The Swift Package Manager is a tool for automating the distribution of Swift code that is well integrated with Swift build system.
Once you have your Swift package set up, adding web3swift
as a dependency is as easy as adding it to the dependencies
value of your Package.swift
.
dependencies: [
.package(url: "https://github.com/web3swift-team/web3swift.git", .upToNextMajor(from: "3.0.0"))
]
Or if your project is not a package follow these guidelines on how to add a Swift Package to your Xcode project.
In the imports section:
import web3swift
import Web3Core
CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:
$ sudo gem install cocoapods
To integrate web3swift into your Xcode project using CocoaPods, specify it in your Podfile
:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '13.0'
target '<Your Target Name>' do
use_frameworks!
pod 'web3swift'
end
Then, run the following command:
$ pod install
WARNING: CocoaPods is a powerful tool for managing dependencies in iOS development, but it also has some limitations that preventing us of providing first class support there. We highly recommend using SPM first as using CocoaPods will delay new updates and bug fixes being delivered to you.
let transaction: CodableTransaction = .emptyTransaction
transaction.from = from ?? transaction.sender // `sender` one is if you have private key of your wallet address, so public key e.g. your wallet address could be interpreted
transaction.value = value
transaction.gasLimitPolicy = .manual(78423)
transaction.gasPricePolicy = .manual(20000000000)
web3.eth.send(transaction)
let contract = web3.contract(Web3.Utils.erc20ABI, at: receipt.contractAddress!)!
let readOp = contract.createReadOperation("name")!
readOp.transaction.from = EthereumAddress("0xe22b8979739D724343bd002F9f432F5990879901")
let response = try await readTX.callContractMethod()
let abiString = "[]" // some ABI string
let bytecode = Data.fromHex("") // some ABI bite sequence
let contract = web3.contract(abiString, at: nil, abiVersion: 2)!
let parameters: [Any] = [...]
let deployOp = contract.prepareDeploy(bytecode: bytecode, constructor: contract.contract.constructor, parameters: parameters)!
deployOp.transaction.from = "" // your address
deployOp.transaction.gasLimitPolicy = .manual(3000000)
let result = try await deployTx.writeToChain(password: "web3swift")
func feeHistory(blockCount: UInt, block: BlockNumber, percentiles:[Double]) async throws -> Web3.Oracle.FeeHistory {
let requestCall: APIRequest = .feeHistory(blockCount, block, percentiles)
let response: APIResponse<Web3.Oracle.FeeHistory> = try await APIRequest.sendRequest(with: web3.provider, for: requestCall) /// explicitly declaring `Result` type is **required**.
return response.result
}
git clone https://github.com/web3swift-team/web3swift.git
cd web3swift
swift build
Documentation is under construction👷🏻👷🏼♀️. We’re trying our best to comment all public API as detailed as we can, but the end it still far to come. But in one of the nearest minor updates we’ll bring DocC support of already done amount of docs. And your PR in such are more than welcome.
Please take a look at Our customers wiki page.
Join our discord and Telegram if you need support or want to contribute to web3swift development!
To do local development and run the local tests, we recommend to use ganache which is also used by CI when running github actions.
// To install
$ npm install ganache --global
// To run
$ ganache
This will create a local blockchain and also some test accounts that are used throughout our tests.
Make sure that ganache
is running on its default port 8546
. To change the port in test cases locate LocalTestCase.swift
and modify the static url
variable.
We are using pre-commit to run validations locally before a commit is created. Please, install pre-commit and run pre-commit install
from project's root directory. After that before every commit git hook will run and execute codespell
, swiftlint
and other checks.
Want to improve? It's awesome: Then good news for you: We are ready to pay for your contribution via @gitcoin bot!
@skywinder are charged with open-sourсe and do not require money for using web3swift library. We want to continue to do everything we can to move the needle forward.
0x6A3738c6299f45c31697aceA647D49EdCC9C28A4
If you believe you have identified a security vulnerability with web3swift, you should report it as soon as possible via email to web3swift@oxor.io. Please do not post it to a public issue tracker.
web3swift is available under the Apache License 2.0 license. See the LICENSE for details.