Latest 0.1.3
Homepage https://github.com/tesseract-one/EthereumWeb3.swift
License Apache 2.0
Platforms ios 8.0, osx 10.10, tvos 9.0, watchos 2.0
Authors

EthereumWeb3.swift

GitHub license
Build Status
GitHub release
CocoaPods version
Platform iOS

Ethereum Web3 Lirary for Swift with Open Wallet support

Goals

This library intergates Boilertalk/Web3.swift library with OpenWallet.swift and Wallet.swift.

It supports major Ethereum Web3 methods through HTTP.

Getting started

Installation

With OpenWallet.swift (Client)

Add the following to your Podfile:

pod 'Tesseract.OpenWallet/Ethereum'
pod 'Tesseract.EthereumWeb3'

# Uncomment this lines if you want to enable PromiseKit extensions
# pod 'Tesseract.OpenWallet/EthereumPromiseKit'
# pod 'Tesseract.EthereumWeb3/PromiseKit'

Then run pod install.

With Wallet.swift (Wallet)

Add the following to your Podfile:

pod 'Tesseract.Wallet/Ethereum'
pod 'Tesseract.EthereumWeb3'

# Uncomment this lines if you want to enable PromiseKit extensions
# pod 'Tesseract.Wallet/EthereumPromiseKit'
# pod 'Tesseract.EthereumWeb3/PromiseKit'

Then run pod install.

Supported methods

For the list of supported methods and API reference check Boilertalk/Web3.swift repository.

Examples

OpenWallet.swift (Client)

New transaction
import OpenWallet
import EthereumWeb3

// HTTP RPC URL
let rpcUrl = "https://mainnet.infura.io/v3/{API-KEY}"

// Initializing OpenWallet with Ethereum. Creating Web3 instance
// Store your OpenWallet instance somewhere(AppDelegate, Context). It should be reused.
// If you need only Web3, you can store it only(it will store OpenWallet inside itself).
let web3 = OpenWallet(networks: [.Ethereum]).ethereum.web3(rpcUrl: rpcUrl)

// Creating Transaction
let tx = EthereumTransaction(
    from: try! EthereumAddress(hex: "0x...", eip55: false),
    to: try! EthereumAddress(hex: "0x...", eip55: false),
    value: 1.eth
)

// Sending it. OpenWallet will handle signing automatically.
web3.eth.sendTransaction(transaction: tx) { response in
    switch response.status {
    case .success(let hash): print("TX Hash:", hash.hex())
    case .failure(let err): print("Error:", error)
    }
}

Wallet.swift (Wallet)

New transaction
import Wallet
import EthereumWeb3

// Path to sqlite database with wallets
let dbPath = "path/to/database.sqlite"

// Wallet Storage
let storage = try! DatabaseWalletStorage(path: dbPath)

// Applying migrations
try! storage.bootstrap()

// Creating manager with Ethereum network support
let manager = try! Manager(networks: [EthereumNetwork()], storage: storage)

// Restoring wallet data from mnemonic
let walletData = try! manager.restoreWalletData(mnemonic: "aba caba ...", password: "12345678")

// Creating wallet from data
let wallet = try! manager.create(from: walletData)

// Unlocking wallet
try! wallet.unlock(password: "12345678")

// Adding first account 
let account = wallet.addAccount()

// HTTP RPC URL
let rpcUrl = "https://mainnet.infura.io/v3/{API-KEY}"

// Creating Web3 for this Wallet
let web3 = wallet.ethereum.web3(rpcUrl: rpcUrl)

// Creating Transaction
let tx = EthereumTransaction(
    from: try! account.eth_address().web3,
    to: try! EthereumAddress(hex: "0x...", eip55: false),
    value: 1.eth
)

// Wallet will sign this transaction automatically (with 'from' account)
web3.eth.sendTransaction(transaction: tx) { response in
    switch response.status {
    case .success(let hash): print("TX Hash:", hash.hex())
    case .failure(let err): print("Error:", error)
    }
}

Author

License

EthereumWeb3.swift is available under the Apache 2.0 license. See the LICENSE file for more information.

Latest podspec

{
    "name": "Tesseract.EthereumWeb3",
    "version": "0.1.3",
    "summary": "Tesseract Ethereum Web3 library with signing support for Swift",
    "description": "Web3 library which can be used with Tesseract Open Wallet or Tesseract Wallet libraries for signing.nSupports eth, net and personal RPC api. Filters handled by polling on client.",
    "homepage": "https://github.com/tesseract-one/EthereumWeb3.swift",
    "license": {
        "type": "Apache 2.0",
        "file": "LICENSE"
    },
    "authors": {
        "Tesseract Systems, Inc.": "[email protected]"
    },
    "source": {
        "git": "https://github.com/tesseract-one/EthereumWeb3.swift.git",
        "tag": "0.1.3"
    },
    "social_media_url": "https://twitter.com/tesseract_one",
    "platforms": {
        "ios": "8.0",
        "osx": "10.10",
        "tvos": "9.0",
        "watchos": "2.0"
    },
    "module_name": "EthereumWeb3",
    "swift_versions": [
        "5.0",
        "5.0"
    ],
    "default_subspecs": "Core",
    "swift_version": "5.0",
    "subspecs": [
        {
            "name": "Core",
            "source_files": "Sources/EthereumWeb3/**/*.swift",
            "dependencies": {
                "Tesseract.EthereumTypes": [
                    "~> 0.1"
                ]
            }
        },
        {
            "name": "PromiseKit",
            "source_files": "Sources/PromiseKit/**/*.swift",
            "dependencies": {
                "Tesseract.EthereumWeb3/Core": [],
                "PromiseKit/CorePromise": [
                    "~> 6.8"
                ]
            }
        }
    ]
}

Pin It on Pinterest

Share This