Swiftpack.co - skywinder/web3swift as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by skywinder.
skywinder/web3swift 3.0.0-RC1
Elegant Web3js functionality in Swift. Native ABI parsing and smart contract interactions.
⭐️ 526
πŸ•“ 1 week ago
iOS macOS
.package(url: "https://github.com/skywinder/web3swift.git", from: "3.0.0-RC1")


web3swift is an iOS toolbelt for interaction with the Ethereum network.

Join our discord if you need a support or want to contribute to web3swift development!

matter-github-swift Web3swift CI Swift Platform CocoaPods Compatible Carthage Compatible License support Stackoverflow

Core features

  • β˜‘ :zap: Swift implementation of web3.js functionality

  • β˜‘ :thought_balloon: 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

  • β˜‘ :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):

    • β˜‘ BIP32 (HD Wallets), BIP39 (Seed phrases), BIP44 (Key generation prefixes)
  • β˜‘ EIP-20 (Standart interface for tokens - ERC-20), EIP-67 (Standard URI scheme), EIP-155 (Replay attacks protection), EIP-2718 (Typed Transaction Envelope), EIP-1559 (Gas Fee market change)

    • β˜‘ 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 Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'

target '<Your Target Name>' do
    pod 'web3swift'

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 "skywinder/web3swift" "master"

Run carthage update --no-use-binaries --platform iOS 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

Example usage

In the imports section:

import web3swift
Send Ether
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(
parameters: [AnyObject](https://raw.github.com/skywinder/web3swift/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(
  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/skywinder/web3swift/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(
  parameters: parameters,
  extraData: extraData,
  transactionOptions: options)!

Write Transaction with your custom contract ABI

Requirement : Your custom contract ABI string

    func contractTransactionMethod(){
        let yourCoin = self.yourbalance.text ?? "0.0" //Get token for sending
        let userDir = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] //get user directory for keystore
        if (FileManager.default.fileExists(atPath: userDir + "/keystore/key.json")) {
            //Create Keystore
            guard let manager = FilestoreWrapper.getKeystoreManager() else {
                print("Manager not found ")
            wethioKeystoreManager = manager
            guard let urlStr = URL(string: "Your rpc url here") else { return }
            guard let kManager = yourKeystoreManager else { return }
            //Create Web3Provider Instance with key manager
            web3ProvideInstance = Web3HttpProvider(urlStr, keystoreManager: kManager)
            guard let wProvier = self.web3ProvideInstance else {return}
            self.web3Instance = Web3(provider: wProvier) //Set provide instance with web3
            guard let wInstance = self.web3Instance else {return}
            self.receiverAddressString = self.walletAddressTF.text //get receiver address string
            print("Receiver address is : ", self.receiverAddressString ?? " ")
            self.etheriumAccountAddress = self.wethioKeystoreManager?.addresses.first?.address  //get sender address in string
            convert address string into etherium addresss
            let senderEthAddress = EthereumAddress(self.etheriumAccountAddress ?? "")
            //Run on backgrounnd tread
            DispatchQueue.global(qos: .background).async {
                do {
                    //Convert receiver address in to etherium address
                    let toaddress = EthereumAddress(self.receiverAddressString ?? "")
                    var options = Web3Options.defaultOptions() //Create web3 options
                    let amountDouble = BigInt((Double(yourCoin) ?? 0.1)*pow(10, 18)) //Convert amount into BIGINT
                    print("Total amount in double value : ", amountDouble)
                    var amount = BigUInt.init(amountDouble) //Convert amount in BIG UI Int
                    let estimateGasPrice = try wInstance.eth.getGasPrice() //estimate gas price
                    guard let eGasReult = self.estimatedGasResult else {
                        print("Unable to find gas price")
                    let nonce = try wInstance.eth.getTransactionCount(address: senderEthAddress) //Get nonce or transaction count
                    print("Is the Transaction count", nonce)
                    let fee = estimateGasPrice * eGasReult
                     - sender address
                     - Gas Result
                     - Gas price
                     - amount
                    var sendTransactionIntermediateOptions = Web3Options.defaultOptions()
                    sendTransactionIntermediateOptions.from = senderEthAddress
                    sendTransactionIntermediateOptions.gasLimit = eGasReult
                    sendTransactionIntermediateOptions.gasPrice = estimateGasPrice
                    var tokenTransactionIntermediate: TransactionIntermediate! //Create transaction intermediate
                    tokenTransactionIntermediate = try wInstance.contract("Your custom contract ABI string", at: contractAddress).method("transfer", args: toaddress, amount, options: sendTransactionIntermediateOptions)
                    let mainTransaction = try tokenTransactionIntermediate.send(options: sendTransactionIntermediateOptions, onBlock: "latest")
                    print(mainTransaction.hash, "is the hash of your transaction")

Web3View example

You can see how to our demo project: WKWebView with injected "web3" provider:

git clone https://github.com/skywinder/web3swift.git
cd web3swift/Example/web3swiftBrowser
pod install
open ./web3swiftBrowser.xcworkspace

Build from source

Default web3swift build

  1. Install carthage:
brew install carthage
  1. Run carthage update:
# Available platforms: `iOS, macOS` 
carthage update --platform iOS --use-xcframeworks
  1. Build project in XCode: Command + B

Build web3swift into .framework:

carthage build --no-skip-current --platform iOS

In case of build errors, please check this solition


  • iOS 9.0+ / macOS 10.11+
  • Xcode 10.2+
  • Swift 5.0+

Migration Guides


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:

Projects that are using web3swift

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.


Join our discord if you need a support or want to contribute to web3swift development!


Want to improve? It's awesome:

Then good news for you: We are ready to pay for your contribution via @gitcoin bot!

If you want to contribute, submit a pull request.


  1. You are more than welcome to participate and get bounty by contributing! Your contribution will be paid via @gitcoin Grant program.
  2. Find or create an issue
  3. You can find open bounties in Gitcoin Bounties list
  4. Commita fix or a new feature in branch, push your changes
  5. Submit a pull request to develop branch

@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.

  • β˜‘ Performance Improvements thanks to @xdozorx for Update perfomance of import account
  • ☐ 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
  • ☐ Convenient methods for namespaces


Security Disclosure

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.


Stars: 527
Last commit: 4 days ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

1 week ago

NOTE: This is the first 3.0.0 release, e.g. it's alpha. We're not guarantee any reliability neither API stability in further versions.

Main features

  • This RC removes Promise concurrency types from the library and replace them to modern async/await concurrency mechanism.
  • Increased minimal OS version that support by the lib: iOS 13, macOS 10.5 (due to async/await).
  • This is the last version which supports Carthage dependency manager, on 3.0.0-RC2 it'll be dropped due to its low prevalence.

What's Changed

Full Changelog: https://github.com/skywinder/web3swift/compare/2.6.4...3.0.0-RC1

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics