Skip to content

Commit f656172

Browse files
committed
fix formatting, add template
1 parent 448c803 commit f656172

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

README.md

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -126,17 +126,24 @@ $ pod install
126126

127127
## Usage
128128

129-
Here's a few use cases of our library
129+
Here's a few use cases of our library:
130+
131+
### Create Account
132+
Create keystore and account with password.
133+
134+
```
135+
```
136+
130137
### Initializing Ethereum address
131-
```bash
138+
```
132139
let coldWalletAddress = EthereumAddress("0x6394b37Cf80A7358b38068f0CA4760ad49983a1B")
133140
let constractAddress = EthereumAddress("0x45245bc59219eeaaf6cd3f382e078a461ff9de7b")
134141
```
135142
Ethereum addresses are checksum checked if they are not lowercased and always length checked
136143

137144

138145
### Setting options
139-
```bash
146+
```
140147
var options = Web3Options.defaultOptions()
141148
// public var to: EthereumAddress? = nil - to what address transaction is aimed
142149
// public var from: EthereumAddress? = nil - form what address it should be sent (either signed locally or on the node)
@@ -148,45 +155,41 @@ options.gasLimit = gasLimit
148155
options.from = EthereumAddress("0xE6877A4d8806e9A9F12eB2e8561EA6c1db19978d")
149156
```
150157
### Getting ETH balance
151-
```bash
158+
```
152159
let address = EthereumAddress("0xE6877A4d8806e9A9F12eB2e8561EA6c1db19978d")!
153160
let web3Main = Web3.InfuraMainnetWeb3()
154161
let balanceResult = web3Main.eth.getBalance(address)
155162
guard case .success(let balance) = balanceResult else {return}
156163
```
157164
### Getting gas price
158-
```bash
159-
let web3Main = Web3.InfuraMainnetWeb3()
165+
```let web3Main = Web3.InfuraMainnetWeb3()
160166
let gasPriceResult = web3Main.eth.getGasPrice()
161167
guard case .success(let gasPrice) = gasPriceResult else {return}
162168
```
163169
### 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
166171
let contract = web3.contract(Web3.Utils.erc20ABI, at: contractAddress, abiVersion: 2)! // utilize precompiled ERC20 ABI for your concenience
167172
guard let bkxBalanceResult = contract.method("balanceOf", parameters: [coldWalletAddress] as [AnyObject], options: options)?.call(options: nil) else {return} // encode parameters for transaction
168173
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
169174
print("BKX token balance = " + String(bal))
170175
```
171176

172177
### Sending ETH
173-
```bash
174-
let web3Rinkeby = Web3.InfuraRinkebyWeb3()
178+
```let web3Rinkeby = Web3.InfuraRinkebyWeb3()
175179
web3Rinkeby.addKeystoreManager(bip32keystoreManager) // attach a keystore if you want to sign locally. Otherwise unsigned request will be sent to remote node
176180
options.from = bip32ks?.addresses?.first! // specify from what address you want to send it
177181
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")
179183
```
180184

181185
### Sending ERC20
182-
```bash
183-
var convenienceTransferOptions = Web3Options.defaultOptions()
186+
```var convenienceTransferOptions = Web3Options.defaultOptions()
184187
convenienceTransferOptions.gasPrice = gasPriceRinkeby
185188
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
186189
let gasEstimateResult = convenienceTokenTransfer!.estimateGas(options: nil)
187190
guard case .success(let gasEstimate) = gasEstimateResult else {return}
188191
convenienceTransferOptions.gasLimit = gasEstimate
189-
let convenienceTransferResult = convenienceTokenTransfer!.send(password: "BANKEXFOUNDATION", options: convenienceTransferOptions)
192+
let convenienceTransferResult = convenienceTokenTransfer!.send(password: "changeme", options: convenienceTransferOptions)
190193
switch convenienceTransferResult {
191194
case .success(let res):
192195
print("Token transfer successful")

0 commit comments

Comments
 (0)