@@ -148,10 +148,10 @@ options.from = walletAddress
148
148
options.gasPrice = .automatic
149
149
options.gasLimit = .automatic
150
150
let tx = contract.write (
151
- " fallback" ,
152
- parameters : [AnyObject ](),
153
- extraData : Data (),
154
- transactionOptions : options)!
151
+ " fallback" ,
152
+ parameters : [AnyObject ](),
153
+ extraData : Data (),
154
+ transactionOptions : options)!
155
155
```
156
156
157
157
##### Send ERC-20 Token
@@ -171,10 +171,10 @@ options.gasPrice = .automatic
171
171
options.gasLimit = .automatic
172
172
let method = " transfer"
173
173
let tx = contract.write (
174
- method,
175
- parameters : [toAddress, amount] as [AnyObject ],
176
- extraData : Data (),
177
- transactionOptions : options)!
174
+ method,
175
+ parameters : [toAddress, amount] as [AnyObject ],
176
+ extraData : Data (),
177
+ transactionOptions : options)!
178
178
```
179
179
180
180
@@ -206,10 +206,79 @@ options.from = walletAddress
206
206
options.gasPrice = .automatic
207
207
options.gasLimit = .automatic
208
208
let tx = contract.write (
209
- contractMethod,
210
- parameters : parameters,
211
- extraData : extraData,
212
- transactionOptions : options)!
209
+ contractMethod,
210
+ parameters : parameters,
211
+ extraData : extraData,
212
+ transactionOptions : options)!
213
+ ```
214
+
215
+
216
+ #### Write Transaction with your custom contract ABI
217
+ #### Requirement : Your custom contract ABI string
218
+ ``` Code
219
+ func contractTransactionMethod(){
220
+ let yourCoin = self.yourbalance.text ?? "0.0" //Get token for sending
221
+ let userDir = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] //get user directory for keystore
222
+ if (FileManager.default.fileExists(atPath: userDir + "/keystore/key.json")) {
223
+ //Create Keystore
224
+ guard let manager = FilestoreWrapper.getKeystoreManager() else {
225
+ print("Manager not found ")
226
+ return
227
+ }
228
+ wethioKeystoreManager = manager
229
+ guard let urlStr = URL(string: "Your rpc url here") else { return }
230
+ guard let kManager = yourKeystoreManager else { return }
231
+
232
+ //Create Web3Provider Instance with key manager
233
+ web3ProvideInstance = Web3HttpProvider(urlStr, keystoreManager: kManager)
234
+ guard let wProvier = self.web3ProvideInstance else {return}
235
+ self.web3Instance = Web3(provider: wProvier) //Set provide instance with web3
236
+ guard let wInstance = self.web3Instance else {return}
237
+ self.receiverAddressString = self.walletAddressTF.text //get receiver address string
238
+ print("Receiver address is : ", self.receiverAddressString ?? " ")
239
+ self.etheriumAccountAddress = self.wethioKeystoreManager?.addresses.first?.address //get sender address in string
240
+ /*
241
+ convert address string into etherium addresss
242
+ */
243
+ let senderEthAddress = EthereumAddress(self.etheriumAccountAddress ?? "")
244
+ //Run on backgrounnd tread
245
+ DispatchQueue.global(qos: .background).async {
246
+ do {
247
+ //Convert receiver address in to etherium address
248
+ let toaddress = EthereumAddress(self.receiverAddressString ?? "")
249
+ var options = Web3Options.defaultOptions() //Create web3 options
250
+ let amountDouble = BigInt((Double(yourCoin) ?? 0.1)*pow(10, 18)) //Convert amount into BIGINT
251
+ print("Total amount in double value : ", amountDouble)
252
+ var amount = BigUInt.init(amountDouble) //Convert amount in BIG UI Int
253
+ let estimateGasPrice = try wInstance.eth.getGasPrice() //estimate gas price
254
+
255
+ guard let eGasReult = self.estimatedGasResult else {
256
+ print("Unable to find gas price")
257
+ return
258
+ }
259
+ let nonce = try wInstance.eth.getTransactionCount(address: senderEthAddress) //Get nonce or transaction count
260
+ print("Is the Transaction count", nonce)
261
+ let fee = estimateGasPrice * eGasReult
262
+ /*
263
+ adding
264
+ - sender address
265
+ - Gas Result
266
+ - Gas price
267
+ - amount
268
+ */
269
+ var sendTransactionIntermediateOptions = Web3Options.defaultOptions()
270
+ sendTransactionIntermediateOptions.from = senderEthAddress
271
+ sendTransactionIntermediateOptions.gasLimit = eGasReult
272
+ sendTransactionIntermediateOptions.gasPrice = estimateGasPrice
273
+ var tokenTransactionIntermediate: TransactionIntermediate! //Create transaction intermediate
274
+ tokenTransactionIntermediate = try wInstance.contract("Your custom contract ABI string", at: contractAddress).method("transfer", args: toaddress, amount, options: sendTransactionIntermediateOptions)
275
+ let mainTransaction = try tokenTransactionIntermediate.send(options: sendTransactionIntermediateOptions, onBlock: "latest")
276
+ print(mainTransaction.hash, "is the hash of your transaction")
277
+ }
278
+ }
279
+ }
280
+ }
281
+
213
282
```
214
283
215
284
### Web3View example
@@ -322,7 +391,7 @@ You are more than welcome to participate! **Your contribution will be paid via
322
391
323
392
- [ ] Convenient methods for namespaces
324
393
325
-
394
+
326
395
327
396
## Credits
328
397
0 commit comments