CocoaPods trunk is moving to be read-only. Read more on the blog, there are 12 months to go.
Maintained by skywinder, Anton Grigorev.
Build Status Swift Platform CocoaPods Compatible Carthage Compatible License support Stackoverflow
web3swift is your toolbelt for any kind interactions with Ethereum network.
If you are using this library in your project, please add a link to this repo.
Nothing makes developers happier than seeing someone else use our work and go wild with it.
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, '9.0' target '<Your Target Name>' do use_frameworks! pod 'web3.swift.pod', '~> 2.2.0' end
Then, run the following command:
$ pod install
Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.
You can install Carthage with Homebrew using the following command:
$ brew update $ brew install carthage
To integrate web3swift into your Xcode project using Carthage, specify it in your Cartfile.
Create an empty Cartfile with the touch command and open it:
$ touch Cartfile $ open -a Xcode Cartfile
Add the following line to the Cartfile and save it:
github "matter-labs/web3swift" "master"
Run carthage update to build the framework. By default, Carthage performs checkouts and builds in a new directory 'Carthage' in the same location as your Cartfile. Open this directory, go to 'Build' directory, choose iOS or macOS directory and use the framework from the chosen directory in your Xcode project.
Full source please look at Documentation folder
Here are quick references for basic features:
You can try lib by running the example project:
git clone https://github.com/matter-labs/web3swift.gitcd web3swift/Example/web3swiftExamplepod installopen ./web3swiftExample.xcworkspaceIs it possible to get a Mnemonic Phrase (Seed Phrase) from Private key using web3swift?
In web3swift there is no backward conversion from Private key to Mnemonic Phrase. Also it is theoretically impossible to recover a phrase from a Private key. After Seed Phrase is converted to some initial entropy the "master key is derived" and the initial entropy is discarded.
The simplest solution is to encrypt the phrase using users pincode and save it in some other secure keystore. Mnemonic Phrase is very sensitive data and you must be very careful to let the user get it. Our advise if you want to show it to a user - ask to save a Passphrase when creating BIP32Keystore.
How to interact with custom smart-contract with web3swift?
For example: you want to interact with smart-contract and all you know is - its address (address example: 0xfa28eC7198028438514b49a3CF353BcA5541ce1d).
You can get the ABI of your contract directly from Remix IDE (Solution)
Then you should use contract address and ABI in creating contract object. In example we use Infura Mainnet:
let yourContractABI: String = <CONTRACT JSON ABI> let toEthereumAddress: EthereumAddress = <DESTINATION ETHEREUM ADDRESS> let abiVersion: Int = <ABI VERSION NUMBER> let contract = Web3.InfuraMainnetWeb3().contract(yourContractABI, at: toEthereumAddress, abiVersion: abiVersion)
Here is the example how you should call some contract method:
let method: String = <CONTRACT METHOD NAME> let parameters: [AnyObject] = <PARAMETERS> let extraData: Data = <DATA> let transactionOptions: TransactionOptions = <OPTIONS> let transaction = contract.read(method, parameters: parameters, extraData: extraData, transactionOptions: transactionOptions)
Here is the example how you should send transaction to some contract method:
let method: String = <CONTRACT METHOD NAME> let parameters: [AnyObject] = <PARAMETERS> let extraData: Data = <DATA> let transactionOptions: TransactionOptions = <OPTIONS> let transaction = contract.write(method, parameters: parameters, extraData: extraData, transactionOptions: transactionOptions)
How to set test local node? You can write something like that:
func setLocalNode(port: Int = 8545) -> Web3? { guard let web3 = Web3(url: URL(string: "http://127.0.0.1:\(port)")!) else { return nil } return web3 }
Alex Vlasov, @shamatar
Petr Korolev, @skywinder
Anton Grigorev, @baldyash
Swift implementation of web3.js functionality
Interaction with remote node via JSON RPC
Local keystore management (geth compatible)
Smart-contract ABI parsing
ABI deconding (V2 is supported with return of structures from public functions. Part of 0.4.22 Solidity compiler)
Ethereum Name Service (ENS) support - a secure & decentralised way to address resources both on and off the blockchain using simple, human-readable names
Interactions (read/write to Smart contracts)
Complete Infura Ethereum API support, patial Websockets API support
Parsing TxPool content into native values (ethereum addresses and transactions) - easy to get pending transactions
Event loops functionality
Supports Web3View functionality - WKWebView with injected "web3" provider
Possibility to add or remove "middleware" that intercepts, modifies and even cancel transaction workflow on stages "before assembly", "after assembly"and "before submission"
Literally following the standards:
RLP encoding
Batched requests in concurrent mode
Base58 encoding scheme
Formatting to and from Ethereum Units
Comprehensive Unit and Integration Test Coverage
If you believe you have identified a security vulnerability with web3swift, you should report it as soon as possible via email to [email protected]. Please do not post it to a public issue tracker.
Matter Labs are charged with open-sourΡe and do not require money for using their web3swift lib. We want to continue to do everything we can to move the needle forward. If you use any of our libraries for work, see if your employers would be interested in donating. Any amount you can donate today to help us reach our goal would be greatly appreciated.
web3swift is available under the Apache License 2.0 license. See the LICENSE for details.