Skip to content

Commit 8d7a985

Browse files
committed
readme updated
1 parent 396a55d commit 8d7a985

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,67 @@ $ pod install
125125

126126
## Usage
127127

128+
Here you can see a few examples of use of our library
129+
### Initializing Ethereum address
130+
```bash
131+
let coldWalletAddress = EthereumAddress("0x6394b37Cf80A7358b38068f0CA4760ad49983a1B")!
132+
let constractAddress = EthereumAddress("0x45245bc59219eeaaf6cd3f382e078a461ff9de7b")!
133+
```
134+
135+
### Getting gas price
136+
```bash
137+
let web3Main = Web3.InfuraMainnetWeb3()
138+
let gasPriceResult = web3Main.eth.getGasPrice()
139+
guard case .success(let gasPrice) = gasPriceResult else {return}
140+
```
141+
### Setting options
142+
```bash
143+
var options = Web3Options.defaultOptions()
144+
options.gasPrice = gasPrice
145+
options.from = EthereumAddress("0xE6877A4d8806e9A9F12eB2e8561EA6c1db19978d")!
146+
let parameters = [] as [AnyObject]
147+
```
148+
149+
### Getting balance
150+
```bash
151+
guard let bkxBalanceResult = contract.method("balanceOf", parameters: [coldWalletAddress] as [AnyObject], options: options)?.call(options: nil) else {return}
152+
guard case .success(let bkxBalance) = bkxBalanceResult, let bal = bkxBalance["0"] as? BigUInt else {return}
153+
print("BKX token balance = " + String(bal))
154+
```
155+
156+
### Sending ETH
157+
```bash
158+
let web3Rinkeby = Web3.InfuraRinkebyWeb3()
159+
160+
web3Rinkeby.addKeystoreManager(bip32keystoreManager)
161+
options.from = bip32ks?.addresses?.first!
162+
intermediateSend = web3Rinkeby.contract(coldWalletABI, at: coldWalletAddress, abiVersion: 2)!.method(options: options)!
163+
let sendResultBip32 = intermediateSend.send(password: "BANKEXFOUNDATION")
164+
switch sendResultBip32 {
165+
case .success(let r):
166+
print(r)
167+
case .failure(let err):
168+
print(err)
169+
}
170+
```
171+
172+
### Sending ERC20
173+
```bash
174+
var convenienceTransferOptions = Web3Options.defaultOptions()
175+
convenienceTransferOptions.gasPrice = gasPriceRinkeby
176+
let convenienceTokenTransfer = web3Rinkeby.eth.sendERC20tokensWithNaturalUnits(tokenAddress: EthereumAddress("0xa407dd0cbc9f9d20cdbd557686625e586c85b20a")!, from: (ks?.addresses?.first!)!, to: EthereumAddress("0x6394b37Cf80A7358b38068f0CA4760ad49983a1B")!, amount: "0.0001", options: convenienceTransferOptions)
177+
let gasEstimateResult2 = convenienceTokenTransfer!.estimateGas(options: nil)
178+
guard case .success(let gasEstimate2) = gasEstimateResult2 else {return}
179+
convenienceTransferOptions.gasLimit = gasEstimate2
180+
let convenienceTransferResult = convenienceTokenTransfer!.send(password: "BANKEXFOUNDATION", options: convenienceTransferOptions)
181+
switch convenienceTransferResult {
182+
case .success(let res):
183+
print("Token transfer successful")
184+
print(res)
185+
case .failure(let error):
186+
print(error)
187+
}
188+
```
128189
129190
## Global plans
130191
- Full reference `web3js` functionality

0 commit comments

Comments
 (0)