Skip to content

Latest commit

 

History

History
 
 

Documentation

Documentation

If you need to find or understand basic Usage, check Usage.md.

Here are quick references for essential features:

Design Decisions

  • Functionality was focused on serializing and signing transactions locally on the device to send raw transactions to the Ethereum network
  • Requirements for password input on every transaction are indeed a design decision. Interface designers can save user passwords with the user's consent
  • Public function for private key export is exposed for user convenience but marked as UNSAFE_. Typical workflow takes care of EIP155 compatibility and proper clearing of private key data from memory

Core features:

  • 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
  • Smart contracts interactions (read/write) 🔄
  • Complete 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:
    • BIP32 HD Wallets: Deterministic Wallet

    • BIP39 (Seed phrases)

    • BIP44 (Key generation prefixes)

    • EIP-20 (A standard interface for tokens - ERC-20)

    • EIP-67 (Standard URI scheme)

    • EIP-155 (Replay attacks protection) enforced!

    • EIP-681 (A standard way of representing various transactions, especially payment requests in Ethers and ERC-20 tokens as URLs)

    • EIP-721 (A standard interface for non-fungible tokens, also known as deeds - ERC-721)

    • EIP-165 (Standard Interface Detection, also known as ERC-165)

    • EIP-777 (New Advanced Token Standard, also known as ERC-777)

    • EIP-820 (Pseudo-introspection Registry Contract, also known as ERC-820)

    • EIP-888 (MultiDimensional Token Standard, also known as ERC-888)

    • EIP-1400 (Security Token Standard, also known as ERC-1400)

    • EIP-1410 (Partially Fungible Token Standard, also known as ERC-1410)

    • EIP-1594 (Core Security Token Standard, also known as ERC-1594)

    • EIP-1643 (Document Management Standard, also known as ERC-1643)

    • EIP-1644 (Controller Token Operation Standard, also known as ERC-1644)

    • EIP-1633 (Re-Fungible Token, also known as ERC-1633)

    • EIP-721x (An extension of ERC721 that adds support for multi-fungible tokens and batch transfers, while being fully backward-compatible, also known as ERC-721x)

    • EIP-1155 (Multi Token Standard, also known as ERC-1155)

    • EIP-1376 (Service-Friendly Token, also known as ERC-1376)

    • ST-20 - ST-20 token is an Ethereum-based token implemented on top of the ERC-20 protocol that adds the ability for tokens to control transfers based on specific rules

Migration Guides

FAQ

Is it possible to get a Mnemonic Phrase (Seed Phrase) from Private key using web3swift?

In web3swift, there is no backward conversion from the 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 the user's pin code and save it in some other secure keystore. The mnemonic phrase is very sensitive data, and you must be very careful to let the user get it. Our advice 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 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 test on a local node?

func setLocalNode(port: Int = 8545) -> Web3? {
    guard let web3 = Web3(url: URL(string: "http://127.0.0.1:\(port)")!) else { return nil }
    return web3
}