Skip to content

Commit 0a524fc

Browse files
committed
Updae documentation clarify readme
1 parent 07e4613 commit 0a524fc

File tree

2 files changed

+80
-4
lines changed

2 files changed

+80
-4
lines changed

Documentation/Usage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ let tx = contract.write(
319319
transactionOptions: options)!
320320
```
321321

322-
##### Read Transaction to call smart contract method
322+
##### Read Transaction from call smart contract method
323323

324324
```swift
325325
let walletAddress = EthereumAddress(wallet.address)! // Your wallet address

README.md

Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
- [Core features](#core-features)
2121
- [Installation](#installation)
2222
- [Example usage](#example-usage)
23+
- [Send Ether](#send-ether)
24+
- [Send ERC-20 Token](#send-erc-20-token)
25+
- [Write Transaction and call smart contract method](#write-transaction-and-call-smart-contract-method)
26+
- [Web3View example:](#web3view-example)
27+
- [Build from source:](#build-from-source)
2328
- [Requirements](#requirements)
2429
- [Migration Guides](#migration-guides)
2530
- [Documentation](#documentation)
@@ -51,7 +56,7 @@
5156

5257
- [x] **[BIP32](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki) (HD Wallets), [BIP39](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki) (Seed phrases), [BIP44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki) (Key generation prefixes)**
5358
- [x] **[EIP-20](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md)** (Standart interface for tokens - ERC-20), **[EIP-67](https://github.com/ethereum/EIPs/issues/67)** (Standard URI scheme), **[EIP-155](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-155.md)** (Replay attacks protection)
54-
- [x] **And many others ** *(For more details about this EIP's look at [Documentation page](https://github.com/matter-labs/web3swift/blob/master/Documentation/))*: EIP-681, EIP-721, EIP-165, EIP-777, EIP-820, EIP-888, EIP-1400, EIP-1410, EIP-1594, EIP-1643, EIP-1644, EIP-1633, EIP-721, EIP-1155, EIP-1376, ST-20
59+
- [x] **And many others** *(For details about this EIP's look at [Documentation page](https://github.com/matter-labs/web3swift/blob/master/Documentation/))*: EIP-681, EIP-721, EIP-165, EIP-777, EIP-820, EIP-888, EIP-1400, EIP-1410, EIP-1594, EIP-1643, EIP-1644, EIP-1633, EIP-721, EIP-1155, EIP-1376, ST-20
5560

5661
- [x] 🗜 **Batched requests** in concurrent mode
5762
- [x] **RLP encoding**
@@ -116,9 +121,80 @@ github "matter-labs/web3swift" "master"
116121

117122
Run `carthage update` to build the framework. By default, Carthage performs checkouts and creates a new directory 'Carthage' in the same location as your Cartfile. Open this directory, go to 'Build' directory, choose iOS or macOS directory, and use the selected directory framework in your Xcode project.
118123

124+
- Swift Package
125+
Open xcode setting and add this repo as a source
126+
119127
### Example usage
120128

121-
**Web3View example:**
129+
130+
##### Send Ether
131+
132+
```swift
133+
let value: String = "1.0" // In Ether
134+
let walletAddress = EthereumAddress(wallet.address)! // Your wallet address
135+
let toAddress = EthereumAddress(toAddressString)!
136+
let contract = web3.contract(Web3.Utils.coldWalletABI, at: toAddress, abiVersion: 2)!
137+
let amount = Web3.Utils.parseToBigUInt(value, units: .eth)
138+
var options = TransactionOptions.defaultOptions
139+
options.value = amount
140+
options.from = walletAddress
141+
options.gasPrice = .automatic
142+
options.gasLimit = .automatic
143+
let tx = contract.write(
144+
"fallback",
145+
parameters: [AnyObject](),
146+
extraData: Data(),
147+
transactionOptions: options)!
148+
```
149+
150+
##### Send ERC-20 Token
151+
152+
```swift
153+
let value: String = "1.0" // In Tokens
154+
let walletAddress = EthereumAddress(wallet.address)! // Your wallet address
155+
let toAddress = EthereumAddress(toAddressString)!
156+
let erc20ContractAddress = EthereumAddress(token.address)!
157+
let contract = web3.contract(Web3.Utils.erc20ABI, at: erc20ContractAddress, abiVersion: 2)!
158+
let amount = Web3.Utils.parseToBigUInt(value, units: .eth)
159+
var options = TransactionOptions.defaultOptions
160+
options.value = amount
161+
options.from = walletAddress
162+
options.gasPrice = .automatic
163+
options.gasLimit = .automatic
164+
let method = "transfer"
165+
let tx = contract.write(
166+
method,
167+
parameters: [toAddress, amount] as [AnyObject],
168+
extraData: Data(),
169+
transactionOptions: options)!
170+
```
171+
172+
##### Write Transaction and call smart contract method
173+
174+
```swift
175+
let value: String = "0.0" // Any amount of Ether you need to send
176+
let walletAddress = EthereumAddress(wallet.address)! // Your wallet address
177+
let contractMethod = "SOMECONTRACTMETHOD" // Contract method you want to write
178+
let contractABI = "..." // Contract ABI
179+
let contractAddress = EthereumAddress(contractAddressString)!
180+
let abiVersion = 2 // Contract ABI version
181+
let parameters: [AnyObject] = [...]() // Parameters for contract method
182+
let extraData: Data = Data() // Extra data for contract method
183+
let contract = web3.contract(contractABI, at: contractAddress, abiVersion: abiVersion)!
184+
let amount = Web3.Utils.parseToBigUInt(value, units: .eth)
185+
var options = TransactionOptions.defaultOptions
186+
options.value = amount
187+
options.from = walletAddress
188+
options.gasPrice = .automatic
189+
options.gasLimit = .automatic
190+
let tx = contract.write(
191+
contractMethod,
192+
parameters: parameters,
193+
extraData: extraData,
194+
transactionOptions: options)!
195+
```
196+
197+
#### Web3View example:
122198

123199
You can see how to our demo project: **WKWebView with injected "web3" provider**:
124200

@@ -132,7 +208,7 @@ open ./web3swiftBrowser.xcworkspace
132208
### Build from source:
133209

134210
- Clone repo
135-
- Instal dependencies via `./carthage-build.sh --platform iOS` (temo workaround, foe of Carthage bug.For more details please look at https://github.com/Carthage/Carthage/issues/3019#issuecomment-665136323)
211+
- Instal dependencies via `./carthage-build.sh --platform iOS` (temp workaround, foe of Carthage bug. [For details please look at](https://github.com/Carthage/Carthage/issues/3019#issuecomment-665136323)
136212

137213
### Requirements
138214

0 commit comments

Comments
 (0)