|
| 1 | +## Design Decisions |
| 2 | + |
| 3 | +- Functionality was focused on serializing and **signing transactions locally** on the device to **send raw transactions** to the Ethereum network |
| 4 | +- **Requirements for password input** on every transaction are indeed a design decision. Interface designers can save user passwords with the user's consent |
| 5 | +- 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 |
| 6 | + |
| 7 | + |
| 8 | +### Core features: |
| 9 | + |
| 10 | +- [x] Swift implementation of [web3.js](https://github.com/ethereum/web3.js/) functionality :zap: |
| 11 | +- [x] Interaction with remote node via **JSON RPC** :thought_balloon: |
| 12 | +- [x] Local **keystore management** (`geth` compatible) |
| 13 | +- [x] Smart-contract **ABI parsing** :book: |
| 14 | +- [x] **ABI deconding** (V2 is supported with return of structures from public functions. Part of 0.4.22 Solidity compiler) |
| 15 | +- [x] Ethereum Name Service **(ENS) support** - a secure & decentralised way to address resources both on and off the blockchain using simple, human-readable names |
| 16 | +- [x] **Smart contracts interactions** (read/write) :arrows_counterclockwise: |
| 17 | +- [x] Complete **Infura support**, patial Websockets API support |
| 18 | +- [x] **Parsing TxPool** content into native values (ethereum addresses and transactions) - easy to get pending transactions |
| 19 | +- [x] **Event loops** functionality |
| 20 | +- [x] Supports Web3View functionality (WKWebView with **injected "web3" provider**) |
| 21 | +- [x] Possibility to **add or remove "middleware" that intercepts**, modifies and even **cancel transaction** workflow on stages "before assembly", "after assembly"and "before submission" |
| 22 | +- [x] **Literally following the standards:** |
| 23 | + - [x] [BIP32](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki) HD Wallets: Deterministic Wallet |
| 24 | + - [x] [BIP39](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki) (Seed phrases) |
| 25 | + - [x] [BIP44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki) (Key generation prefixes) |
| 26 | + - [x] [EIP-20](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md) (A standard interface for tokens - ERC-20) |
| 27 | + - [x] [EIP-67](https://github.com/ethereum/EIPs/issues/67) (Standard URI scheme) |
| 28 | + - [x] [EIP-155](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-155.md) (Replay attacks protection) *enforced!* |
| 29 | + - [x] [EIP-681](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-681.md) (A standard way of representing various transactions, especially payment requests in Ethers and ERC-20 tokens as URLs) |
| 30 | + - [x] [EIP-721](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md) (A standard interface for non-fungible tokens, also known as deeds - ERC-721) |
| 31 | + - [x] [EIP-165](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-165.md) (Standard Interface Detection, also known as ERC-165) |
| 32 | + - [x] [EIP-777](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-777.md) (New Advanced Token Standard, also known as ERC-777) |
| 33 | + - [x] [EIP-820](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-820.md) (Pseudo-introspection Registry Contract, also known as ERC-820) |
| 34 | + - [x] [EIP-888](https://github.com/ethereum/EIPs/issues/888) (MultiDimensional Token Standard, also known as ERC-888) |
| 35 | + - [x] [EIP-1400](https://github.com/ethereum/EIPs/issues/1411) (Security Token Standard, also known as ERC-1400) |
| 36 | + - [x] [EIP-1410](https://github.com/ethereum/EIPs/issues/1410) (Partially Fungible Token Standard, also known as ERC-1410) |
| 37 | + - [x] [EIP-1594](https://github.com/ethereum/EIPs/issues/1594) (Core Security Token Standard, also known as ERC-1594) |
| 38 | + - [x] [EIP-1643](https://github.com/ethereum/EIPs/issues/1643) (Document Management Standard, also known as ERC-1643) |
| 39 | + - [x] [EIP-1644](https://github.com/ethereum/EIPs/issues/1644) (Controller Token Operation Standard, also known as ERC-1644) |
| 40 | + - [x] [EIP-1633](https://github.com/ethereum/EIPs/issues/1634) (Re-Fungible Token, also known as ERC-1633) |
| 41 | + - [x] [EIP-721x](https://github.com/loomnetwork/erc721x) (An extension of ERC721 that adds support for multi-fungible tokens and batch transfers, while being fully backward-compatible, also known as ERC-721x) |
| 42 | + - [x] [EIP-1155](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1155.md) (Multi Token Standard, also known as ERC-1155) |
| 43 | + - [x] [EIP-1376](https://github.com/ethereum/EIPs/issues/1376) (Service-Friendly Token, also known as ERC-1376) |
| 44 | + - [x] [ST-20](https://github.com/PolymathNetwork/polymath-core) - 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 |
| 45 | + |
| 46 | +## FAQ |
| 47 | + |
| 48 | +> Is it possible to get a Mnemonic Phrase (Seed Phrase) from Private key using web3swift? |
| 49 | +
|
| 50 | +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**. |
| 51 | + |
| 52 | +The simplest solution is to encrypt the phrase using the user's pin code and save it in some other secure keystore. |
| 53 | +The mnemonic phrase is very sensitive data, and you must be very careful to let the user get it. |
| 54 | +Our advice if you want to show it to a user - ask to save a Passphrase when creating BIP32Keystore. |
| 55 | + |
| 56 | +> How to interact with custom smart-contract with web3swift? |
| 57 | +
|
| 58 | +For example: you want to interact with smart-contract and all you know is - its address (address example: 0xfa28eC7198028438514b49a3CF353BcA5541ce1d). |
| 59 | + |
| 60 | +You can get the ABI of your contract directly from [Remix IDE](https://remix.ethereum.org/) ([Solution](https://ethereum.stackexchange.com/questions/27536/where-to-find-contract-abi-in-new-version-of-online-remix-solidity-compiler?rq=1)) |
| 61 | + |
| 62 | +Then you should use contract address and ABI in creating contract object. In example we use Infura Mainnet: |
| 63 | + |
| 64 | +```swift |
| 65 | +let yourContractABI: String = <CONTRACT JSON ABI> |
| 66 | +let toEthereumAddress: EthereumAddress = <DESTINATION ETHEREUM ADDRESS> |
| 67 | +let abiVersion: Int = <ABI VERSION NUMBER> |
| 68 | + |
| 69 | +let contract = Web3.InfuraMainnetWeb3().contract(yourContractABI, at: toEthereumAddress, abiVersion: abiVersion) |
| 70 | +``` |
| 71 | + |
| 72 | +Here is the example how you should call contract method: |
| 73 | + |
| 74 | +```swift |
| 75 | +let method: String = <CONTRACT METHOD NAME> |
| 76 | +let parameters: [AnyObject] = <PARAMETERS> |
| 77 | +let extraData: Data = <DATA> |
| 78 | +let transactionOptions: TransactionOptions = <OPTIONS> |
| 79 | + |
| 80 | +let transaction = contract.read(method, parameters: parameters, extraData: extraData, transactionOptions: transactionOptions) |
| 81 | +``` |
| 82 | + |
| 83 | +Here is the example how you should send transaction to some contract method: |
| 84 | + |
| 85 | +```swift |
| 86 | +let method: String = <CONTRACT METHOD NAME> |
| 87 | +let parameters: [AnyObject] = <PARAMETERS> |
| 88 | +let extraData: Data = <DATA> |
| 89 | +let transactionOptions: TransactionOptions = <OPTIONS> |
| 90 | +let transaction = contract.write(method, parameters: parameters, extraData: extraData, transactionOptions: transactionOptions) |
| 91 | +``` |
| 92 | + |
| 93 | +> How to test on a local node? |
| 94 | +
|
| 95 | +```swift |
| 96 | +func setLocalNode(port: Int = 8545) -> Web3? { |
| 97 | + guard let web3 = Web3(url: URL(string: "http://127.0.0.1:\(port)")!) else { return nil } |
| 98 | + return web3 |
| 99 | +} |
| 100 | +``` |
| 101 | + |
0 commit comments