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
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.
118
123
124
+
- Swift Package
125
+
Open xcode setting and add this repo as a source
126
+
119
127
### Example usage
120
128
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 web3 = Web3.InfuraMainnetWeb3()
154
+
let value: String="1.0"// In Tokens
155
+
let walletAddress =EthereumAddress(wallet.address)!// Your wallet address
156
+
let toAddress =EthereumAddress(toAddressString)!
157
+
let erc20ContractAddress =EthereumAddress(token.address)!
158
+
let contract = web3.contract(Web3.Utils.erc20ABI, at: erc20ContractAddress, abiVersion: 2)!
159
+
let amount = Web3.Utils.parseToBigUInt(value, units: .eth)
160
+
var options = TransactionOptions.defaultOptions
161
+
options.value= amount
162
+
options.from= walletAddress
163
+
options.gasPrice= .automatic
164
+
options.gasLimit= .automatic
165
+
let method ="transfer"
166
+
let tx = contract.write(
167
+
method,
168
+
parameters: [toAddress, amount] as [AnyObject],
169
+
extraData: Data(),
170
+
transactionOptions: options)!
171
+
```
172
+
173
+
174
+
##### Get account balance
175
+
```swift
176
+
let web3 = Web3.InfuraMainnetWeb3()
177
+
let address =EthereumAddress("<Address>")!
178
+
let balance =try web3.eth.getBalance(address: address)
179
+
let balanceString = Web3.Utils.formatToEthereumUnits(balance, toUnits: .eth, decimals: 3)
180
+
```
181
+
182
+
##### Write Transaction and call smart contract method
183
+
184
+
```swift
185
+
let web3 = Web3.InfuraMainnetWeb3()
186
+
let value: String="0.0"// Any amount of Ether you need to send
187
+
let walletAddress =EthereumAddress(wallet.address)!// Your wallet address
188
+
let contractMethod ="SOMECONTRACTMETHOD"// Contract method you want to write
189
+
let contractABI ="..."// Contract ABI
190
+
let contractAddress =EthereumAddress(contractAddressString)!
191
+
let abiVersion =2// Contract ABI version
192
+
let parameters: [AnyObject] = [...]() // Parameters for contract method
193
+
let extraData: Data =Data() // Extra data for contract method
194
+
let contract = web3.contract(contractABI, at: contractAddress, abiVersion: abiVersion)!
195
+
let amount = Web3.Utils.parseToBigUInt(value, units: .eth)
196
+
var options = TransactionOptions.defaultOptions
197
+
options.value= amount
198
+
options.from= walletAddress
199
+
options.gasPrice= .automatic
200
+
options.gasLimit= .automatic
201
+
let tx = contract.write(
202
+
contractMethod,
203
+
parameters: parameters,
204
+
extraData: extraData,
205
+
transactionOptions: options)!
206
+
```
207
+
208
+
### Web3View example
122
209
123
210
You can see how to our demo project: **WKWebView with injected "web3" provider**:
124
211
@@ -129,10 +216,10 @@ pod install
129
216
open ./web3swiftBrowser.xcworkspace
130
217
```
131
218
132
-
### Build from source:
219
+
### Build from source
133
220
134
221
- Clone repo
135
-
- Instal dependencies via `./carthage-build.sh --platform iOS` (temo workaround, foe of Carthage bug.For more details please look athttps://github.com/Carthage/Carthage/issues/3019#issuecomment-665136323)
222
+
- 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)
136
223
137
224
### Requirements
138
225
@@ -206,9 +293,9 @@ If you use any of our libraries for work, see if your employers would be interes
206
293
We want to continue to do everything we can to move the needle forward.
207
294
208
295
-**Support us** via [@gitcoin Grant program](https://gitcoin.co/grants/358/web3swift)
0 commit comments