web3swift is an iOS toolbelt for interaction with the Ethereum network.
- Core features
- Projects that are using web3swift
- Security Disclosure
☑ :zap: Swift implementation of web3.js functionality
☑ :thought_balloon: Interaction with remote node via JSON RPC
☑ 🔐 Local keystore management (
☑ 🤖 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
☑ :arrows_counterclockwise: Smart contracts interactions (read/write)
☑ ⛩ Infura 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 (BIP, EIP, etc):
- ☑ And many others (For details about this EIP's look at Documentation page): EIP-681, EIP-721, EIP-165, EIP-777, EIP-820, EIP-888, EIP-1400, EIP-1410, EIP-1594, EIP-1643, EIP-1644, EIP-1633, EIP-721, EIP-1155, EIP-1376, ST-20
☑ 🗜 Batched requests in concurrent mode
☑ RLP encoding
☑ Base58 encoding scheme
☑ Formatting to and from Ethereum Units
☑ Comprehensive Unit and Integration Test Coverage
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
source 'https://github.com/CocoaPods/Specs.git' platform :ios, '9.0' target '<Your Target Name>' do use_frameworks! pod 'web3swift' 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
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"
carthage update to build the framework. By default, Carthage performs checkouts and creates 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 selected directory framework in your Xcode project.
- Swift Package Open xcode setting and add this repo as a source
let value: String = "1.0" // In Ether let walletAddress = EthereumAddress(wallet.address)! // Your wallet address let toAddress = EthereumAddress(toAddressString)! let contract = web3.contract(Web3.Utils.coldWalletABI, at: toAddress, abiVersion: 2)! let amount = Web3.Utils.parseToBigUInt(value, units: .eth) var options = TransactionOptions.defaultOptions options.value = amount options.from = walletAddress options.gasPrice = .automatic options.gasLimit = .automatic let tx = contract.write( "fallback", parameters: [AnyObject](https://raw.github.com/matter-labs/web3swift/blob/develop/), extraData: Data(), transactionOptions: options)!
Send ERC-20 Token
let web3 = Web3.InfuraMainnetWeb3() let value: String = "1.0" // In Tokens let walletAddress = EthereumAddress(wallet.address)! // Your wallet address let toAddress = EthereumAddress(toAddressString)! let erc20ContractAddress = EthereumAddress(token.address)! let contract = web3.contract(Web3.Utils.erc20ABI, at: erc20ContractAddress, abiVersion: 2)! let amount = Web3.Utils.parseToBigUInt(value, units: .eth) var options = TransactionOptions.defaultOptions options.value = amount options.from = walletAddress options.gasPrice = .automatic options.gasLimit = .automatic let method = "transfer" let tx = contract.write( method, parameters: [toAddress, amount] as [AnyObject], extraData: Data(), transactionOptions: options)!
Get account balance
let web3 = Web3.InfuraMainnetWeb3() let address = EthereumAddress("<Address>")! let balance = try web3.eth.getBalance(address: address) let balanceString = Web3.Utils.formatToEthereumUnits(balance, toUnits: .eth, decimals: 3)
Write Transaction and call smart contract method
let web3 = Web3.InfuraMainnetWeb3() let value: String = "0.0" // Any amount of Ether you need to send let walletAddress = EthereumAddress(wallet.address)! // Your wallet address let contractMethod = "SOMECONTRACTMETHOD" // Contract method you want to write let contractABI = "..." // Contract ABI let contractAddress = EthereumAddress(contractAddressString)! let abiVersion = 2 // Contract ABI version let parameters: [AnyObject] = [...](https://raw.github.com/matter-labs/web3swift/blob/develop/) // Parameters for contract method let extraData: Data = Data() // Extra data for contract method let contract = web3.contract(contractABI, at: contractAddress, abiVersion: abiVersion)! let amount = Web3.Utils.parseToBigUInt(value, units: .eth) var options = TransactionOptions.defaultOptions options.value = amount options.from = walletAddress options.gasPrice = .automatic options.gasLimit = .automatic let tx = contract.write( contractMethod, parameters: parameters, extraData: extraData, transactionOptions: options)!
You can see how to our demo project: WKWebView with injected "web3" provider:
git clone https://github.com/matter-labs/web3swift.git cd web3swift/Example/web3swiftBrowser pod install open ./web3swiftBrowser.xcworkspace
Build from source
- Clone repo
- Instal dependencies via
./carthage-build.sh --platform iOS(temp workaround, foe of Carthage bug. For details please look at
- iOS 9.0+ / macOS 10.11+
- Xcode 10.2+
- Swift 5.0+
For full documentation details and FAQ, please look at Documentation
If you need to find or understand an API, check Usage.md.
FAQ moved Documentation Page
Here are quick references for essential features:
- Preffered models
- Account Management (create, import, private keys managments, etc.)
- Ethereum Endpoints interaction (web3, balance, tx's operations, chain state)
Projects that are using web3swift
If you are using this library in your project, please add a link to this repo.
- Peepeth iOS client
- Ethereum & ERC20Tokens Wallet
- UP Wallet/loopr-ios
- MyENS Wallet
- Biomedical Data Sharing dApp - Geolocation
- Alice Wallet
- YOUR APP CAN BE THERE (click me) :wink:
Nothing makes developers happier than seeing someone else use our work and go wild with it.
- If you need help, open an issue.
- If you'd like to see web3swift best practices, check Projects that using web3swift.
- If you found a bug, open an issue.
Want to improve? It's awesome:
Then good news for you: We are ready to pay for your contribution via @gitcoin bot!
If you have a feature request, open an issue.
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 much appreciated.
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.
- Support us via @gitcoin Grant program
- Ether wallet address:
You are more than welcome to participate! Your contribution will be paid via @gitcoin Grant program.
☐ L2 support (such as ZkSync)
☐ Modularity with the basic Web3 subspec/SPM (the most basic functions like transaction signing and interacting with an http rpc server) and other modules with additional functionality
☐ Complete Documentation (https://web3swift.github.io/web3swift)
☐ Performance Improvements
☐ Convenient methods for namespaces
If you believe you have identified a security vulnerability with web3swift, you should report it as soon as possible via email to email@example.com. 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.
You may find interesting
2.2.1 - 2019-06-24 09:47:14
- Updated Infura endpoints
- Updated BigInt to 4.0
- New ENS resolver ABI
- New ENS resolver interfaceImplementer function
- Exposed errorDescription
- Signature fix
2.2.0 - 2019-04-30 11:17:20
- Removed pods
- Complete carthage support
- Removed old examples
2.1.6 - 2019-04-26 08:25:56
Made most of ENS namespace classes props and methods public
2.1.5 - 2019-04-24 22:14:39
- Updated ENS support
- Fixed Travis build
- Removed EthereumABI, EthereumAddress, SwiftRLP pods
- Updated pods
- Warnings fixed
2.1.3 - 2019-04-06 19:16:36
- Docs updated
2.1.2 - 2019-03-30 08:57:41
Swift 5.0 update
2.1.1 - 2019-03-26 15:11:28
- Removed deprecated
- Added ST-20 class
- Fixed spelling
- Made some functions customisable
- Fixed podspec and project
2.1.0 - 2019-03-06 11:16:32
- Added a lot of EIPs
- Updated docs
Better fix for TX value - 2018-11-20 12:41:01
2.0.3 - 2018-11-20 11:17:28
2.0.2 pointing to develop
Fixes before web3webview - 2018-11-20 11:14:54
- Fix gas estimation
Return of ENS - 2018-11-05 21:23:45
- Restore ENS functionality
- Long awaited nonce management middleware
- Add post-submission hook functions too
Initial 2.0 - 2018-10-30 10:45:47
- The most important - now you have to do "import Web3swift" (capitalization!) to follow naming convention
- Put the groundwork for implementing hooks and event loops functionality
- In the next minor release WKWebView with injected "web3" provider will be available by default
- One can add or remove "middleware" that intercepts, modifies and even cancel transaction workflow on stages "before assembly" (before obtaining nonce, gas price, etc), "after assembly" (when nonce and gas price is set for transaction) and "before submission" (right before transaction is either signed locally and is sent as raw, or just send to remote node)
- Usage of "Result" framework was removed due to large amount if name conflicts
- Now functions throw instead of returning "Result" wrapper
- "Web3Options" are no longer used, instead two new classes introduced: "ReadTransaction" and "WriteTransaction", that have a variable "transactionOptions" used to specify gas price, limit, nonce policy, value
- ENS functionality is disabled for now, until the next patch version
Visibility fixes - 2018-10-22 18:07:12
Fix function visibilities for some ERC20, ERC721 and ENS functions
Last before refactoring - 2018-10-18 13:26:33
It's a last update before refactoring for 2.0 version with breaking API changes
- Tx pool tools (Infura has no access to Tx pool, be aware)
- ERC721 mapping to native Swift class
Modularity - 2018-10-04 14:14:00
- Start splitting to modules
- Preliminary ENS support
- Fix formatting in scientific fallback mode
XCode 10 - 2018-09-18 12:52:42
- Update dependencies for XCode 10
- May require Cocoapods 1.6 beta
EIP681 - 2018-09-13 16:49:25
- Implements EIP681 code parsing
- Fixes initialization of non-checksummed Ethereum addresses
- !!! IMPORTANT !!! changes default passwords for all the keystores
Password derivation degradation fix - 2018-09-04 19:19:44
improve performance of Scrypt KDF