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
let address = EthereumAddress("0xE6877A4d8806e9A9F12eB2e8561EA6c1db19978d")!
153
160
let web3Main = Web3.InfuraMainnetWeb3()
154
161
let balanceResult = web3Main.eth.getBalance(address)
155
162
guard case .success(let balance) = balanceResult else {return}
156
163
```
157
164
### Getting gas price
158
-
```bash
159
-
let web3Main = Web3.InfuraMainnetWeb3()
165
+
```let web3Main = Web3.InfuraMainnetWeb3()
160
166
let gasPriceResult = web3Main.eth.getGasPrice()
161
167
guard case .success(let gasPrice) = gasPriceResult else {return}
162
168
```
163
169
### Getting ERC20 token balance
164
-
```bash
165
-
let contractAddress = EthereumAddress("0x45245bc59219eeaaf6cd3f382e078a461ff9de7b")! // BKX token on Ethereum mainnet
170
+
```let contractAddress = EthereumAddress("0x45245bc59219eeaaf6cd3f382e078a461ff9de7b")! // BKX token on Ethereum mainnet
166
171
let contract = web3.contract(Web3.Utils.erc20ABI, at: contractAddress, abiVersion: 2)! // utilize precompiled ERC20 ABI for your concenience
167
172
guard let bkxBalanceResult = contract.method("balanceOf", parameters: [coldWalletAddress] as [AnyObject], options: options)?.call(options: nil) else {return} // encode parameters for transaction
168
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
169
174
print("BKX token balance = " + String(bal))
170
175
```
171
176
172
177
### Sending ETH
173
-
```bash
174
-
let web3Rinkeby = Web3.InfuraRinkebyWeb3()
178
+
```let web3Rinkeby = Web3.InfuraRinkebyWeb3()
175
179
web3Rinkeby.addKeystoreManager(bip32keystoreManager) // attach a keystore if you want to sign locally. Otherwise unsigned request will be sent to remote node
176
180
options.from = bip32ks?.addresses?.first! // specify from what address you want to send it
177
181
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
178
-
let sendResultBip32 = intermediateSend.send(password: "BANKEXFOUNDATION")
182
+
let sendResultBip32 = intermediateSend.send(password: "changeme")
179
183
```
180
184
181
185
### Sending ERC20
182
-
```bash
183
-
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
186
189
let gasEstimateResult = convenienceTokenTransfer!.estimateGas(options: nil)
187
190
guard case .success(let gasEstimate) = gasEstimateResult else {return}
188
191
convenienceTransferOptions.gasLimit = gasEstimate
189
-
let convenienceTransferResult = convenienceTokenTransfer!.send(password: "BANKEXFOUNDATION", options: convenienceTransferOptions)
192
+
let convenienceTransferResult = convenienceTokenTransfer!.send(password: "changeme", options: convenienceTransferOptions)
0 commit comments