You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+35-15Lines changed: 35 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -132,6 +132,7 @@ Here's a few use cases of our library:
132
132
Create keystore and account with password.
133
133
134
134
```
135
+
//TODO
135
136
```
136
137
137
138
### Initializing Ethereum address
@@ -162,28 +163,35 @@ let balanceResult = web3Main.eth.getBalance(address)
162
163
guard case .success(let balance) = balanceResult else {return}
163
164
```
164
165
### Getting gas price
165
-
```let web3Main = Web3.InfuraMainnetWeb3()
166
+
```
167
+
let web3Main = Web3.InfuraMainnetWeb3()
166
168
let gasPriceResult = web3Main.eth.getGasPrice()
167
169
guard case .success(let gasPrice) = gasPriceResult else {return}
168
170
```
169
-
### Getting ERC20 token balance
170
-
```let contractAddress = EthereumAddress("0x45245bc59219eeaaf6cd3f382e078a461ff9de7b")! // BKX token on Ethereum mainnet
171
-
let contract = web3.contract(Web3.Utils.erc20ABI, at: contractAddress, abiVersion: 2)! // utilize precompiled ERC20 ABI for your concenience
172
-
guard let bkxBalanceResult = contract.method("balanceOf", parameters: [coldWalletAddress] as [AnyObject], options: options)?.call(options: nil) else {return} // encode parameters for transaction
173
-
guard case .success(let bkxBalance) = bkxBalanceResult, let bal = bkxBalance["0"] as? BigUInt else {return} // bkxBalance is [String: Any], and parameters are enumerated as "0", "1", etc in order of being returned. If returned parameter has a name in ABI, it is also duplicated
174
-
print("BKX token balance = " + String(bal))
175
-
```
176
171
177
172
### Sending ETH
178
-
```let web3Rinkeby = Web3.InfuraRinkebyWeb3()
173
+
```
174
+
let web3Rinkeby = Web3.InfuraRinkebyWeb3()
179
175
web3Rinkeby.addKeystoreManager(bip32keystoreManager) // attach a keystore if you want to sign locally. Otherwise unsigned request will be sent to remote node
180
176
options.from = bip32ks?.addresses?.first! // specify from what address you want to send it
181
177
intermediateSend = web3Rinkeby.contract(Web3.Utils.coldWalletABI, at: coldWalletAddress, abiVersion: 2)!.method(options: options)! // an address with a private key attached in not different from any other address, just has very simple ABI
182
178
let sendResultBip32 = intermediateSend.send(password: "changeme")
let contractAddress = EthereumAddress("0x45245bc59219eeaaf6cd3f382e078a461ff9de7b")! // BKX token on Ethereum mainnet
186
+
let contract = web3.contract(Web3.Utils.erc20ABI, at: contractAddress, abiVersion: 2)! // utilize precompiled ERC20 ABI for your concenience
187
+
guard let bkxBalanceResult = contract.method("balanceOf", parameters: [coldWalletAddress] as [AnyObject], options: options)?.call(options: nil) else {return} // encode parameters for transaction
188
+
guard case .success(let bkxBalance) = bkxBalanceResult, let bal = bkxBalance["0"] as? BigUInt else {return} // bkxBalance is [String: Any], and parameters are enumerated as "0", "1", etc in order of being returned. If returned parameter has a name in ABI, it is also duplicated
189
+
print("BKX token balance = " + String(bal))
190
+
```
191
+
192
+
#### Sending ERC20
193
+
```
194
+
var convenienceTransferOptions = Web3Options.defaultOptions()
let convenienceTokenTransfer = web3Rinkeby.eth.sendERC20tokensWithNaturalUnits(tokenAddress: EthereumAddress("0xa407dd0cbc9f9d20cdbd557686625e586c85b20a")!, from: (ks?.addresses?.first!)!, to: EthereumAddress("0x6394b37Cf80A7358b38068f0CA4760ad49983a1B")!, amount: "0.0001", options: convenienceTransferOptions) // there are also convenience functions to send ETH and ERC20 under the .eth structure
189
197
let gasEstimateResult = convenienceTokenTransfer!.estimateGas(options: nil)
*[YOUR APP CAN BE THERE (click me)](https://github.com/matterinc/web3swift/issues):wink:
207
219
208
220
If you've used this project in a live app, please let us know!
209
221
210
222
*If you are using `web3swift` in your app or know of an app that uses it, please add it to [this](https://github.com/matterinc/web3swift/wiki/Apps-using-web3swift) list.*
211
223
224
+
225
+
226
+
## Future plans
227
+
228
+
- Full reference `web3js` functionality
229
+
- Light Ethereum subprotocol (LES) integration
230
+
231
+
212
232
## Special thanks to
213
233
214
234
- Gnosis team and their library [Bivrost-swift](https://github.com/gnosis/bivrost-swift) for inspiration for the ABI decoding approach
0 commit comments