@@ -209,77 +209,82 @@ transactionOptions: options)!
209
209
#### Write Transaction with your custom contract ABI
210
210
#### Requirement : Your custom contract ABI string
211
211
``` Code
212
- let yourCoin = self.yourbalance.text ?? "0.0" //Get token for sending
213
- let userDir = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] //get user directory for keystore
214
- if (FileManager.default.fileExists(atPath: userDir + "/keystore/key.json")) {
215
- //Create Keystore
216
- guard let manager = FilestoreWrapper.getKeystoreManager() else {
217
- print("Manager not found ")
218
- return
219
- }
220
- wethioKeystoreManager = manager
221
- guard let urlStr = URL(string: "Your rpc url here") else { return }
222
- guard let kManager = yourKeystoreManager else { return }
223
-
224
- //Create Web3Provider Instance with key manager
225
- web3ProvideInstance = Web3HttpProvider(urlStr, keystoreManager: kManager)
226
- guard let wProvier = self.web3ProvideInstance else {return}
227
- self.web3Instance = Web3(provider: wProvier) //Set provide instance with web3
228
- guard let wInstance = self.web3Instance else {return}
229
- self.receiverAddressString = self.walletAddressTF.text //get receiver address string
230
- print("Receiver address is : ", self.receiverAddressString ?? " ")
231
- self.etheriumAccountAddress = self.wethioKeystoreManager?.addresses.first?.address //get sender address in string
232
-
233
-
234
- //convert address string into etherium addresss
235
- let senderEthAddress = EthereumAddress(self.etheriumAccountAddress ?? "")
236
- DispatchQueue.global(qos: .background).async {
237
- do {
238
- //Convert receiver address in to etherium address
239
- let toaddress = EthereumAddress(self.receiverAddressString ?? "")
240
-
241
- //Create web3 options
242
- var options = Web3Options.defaultOptions()
243
-
244
- //Convert amount into BIGINT
245
- let amountDouble = BigInt((Double(yourCoin) ?? 0.1)*pow(10, 18))
246
-
247
- //Here i am using 0.1 as an default value please use validation for amount (coin or token)
248
- print("Total amount in double value : ", amountDouble)
249
-
250
- //Convert amount in BIG UI iNt
251
- var amount = BigUInt.init(amountDouble)
252
-
253
- //get gas price
254
- let estimateGasPrice = try wInstance.eth.getGasPrice()
255
- guard let eGasReult = self.estimatedGasResult else {
256
- print("Unable to find gas price")
257
- return
258
- }
259
-
260
- //Get nonce
261
- let nonce = try wInstance.eth.getTransactionCount(address: senderEthAddress)
262
- print("Is the Transaction count", nonce)
263
- let fee = estimateGasPrice * eGasReult
264
- /*
265
- adding
266
- - sender address
267
- - Gas Result
268
- - Gas price
269
- - amount
270
- */
271
- var sendTransactionIntermediateOptions = Web3Options.defaultOptions()
272
- sendTransactionIntermediateOptions.from = senderEthAddress
273
- sendTransactionIntermediateOptions.gasLimit = eGasReult
274
- sendTransactionIntermediateOptions.gasPrice = estimateGasPrice
275
-
276
- var tokenTransactionIntermediate: TransactionIntermediate!
277
- tokenTransactionIntermediate = try wInstance.contract("Your custom contract ABI string", at: contractAddress).method("transfer", args: toaddress, amount, options: sendTransactionIntermediateOptions)
278
-
279
- let mainTransaction = try tokenTransactionIntermediate.send(options: sendTransactionIntermediateOptions, onBlock: "latest")
280
-
281
- print(mainTransaction.hash, "is the hash")
282
- }
212
+ func contractTransactionMethod(){
213
+ let yourCoin = self.yourbalance.text ?? "0.0" //Get token for sending
214
+ let userDir = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] //get user directory for keystore
215
+ if (FileManager.default.fileExists(atPath: userDir + "/keystore/key.json")) {
216
+ //Create Keystore
217
+ guard let manager = FilestoreWrapper.getKeystoreManager() else {
218
+ print("Manager not found ")
219
+ return
220
+ }
221
+ wethioKeystoreManager = manager
222
+ guard let urlStr = URL(string: "Your rpc url here") else { return }
223
+ guard let kManager = yourKeystoreManager else { return }
224
+
225
+ //Create Web3Provider Instance with key manager
226
+ web3ProvideInstance = Web3HttpProvider(urlStr, keystoreManager: kManager)
227
+ guard let wProvier = self.web3ProvideInstance else {return}
228
+ self.web3Instance = Web3(provider: wProvier) //Set provide instance with web3
229
+ guard let wInstance = self.web3Instance else {return}
230
+ self.receiverAddressString = self.walletAddressTF.text //get receiver address string
231
+ print("Receiver address is : ", self.receiverAddressString ?? " ")
232
+ self.etheriumAccountAddress = self.wethioKeystoreManager?.addresses.first?.address //get sender address in string
233
+
234
+
235
+ //convert address string into etherium addresss
236
+ let senderEthAddress = EthereumAddress(self.etheriumAccountAddress ?? "")
237
+ DispatchQueue.global(qos: .background).async {
238
+ do {
239
+ //Convert receiver address in to etherium address
240
+ let toaddress = EthereumAddress(self.receiverAddressString ?? "")
241
+
242
+ //Create web3 options
243
+ var options = Web3Options.defaultOptions()
244
+
245
+ //Convert amount into BIGINT
246
+ let amountDouble = BigInt((Double(yourCoin) ?? 0.1)*pow(10, 18))
247
+
248
+ //Here i am using 0.1 as an default value please use validation for amount (coin or token)
249
+ print("Total amount in double value : ", amountDouble)
250
+
251
+ //Convert amount in BIG UI iNt
252
+ var amount = BigUInt.init(amountDouble)
253
+
254
+ //get gas price
255
+ let estimateGasPrice = try wInstance.eth.getGasPrice()
256
+ guard let eGasReult = self.estimatedGasResult else {
257
+ print("Unable to find gas price")
258
+ return
259
+ }
260
+
261
+ //Get nonce
262
+ let nonce = try wInstance.eth.getTransactionCount(address: senderEthAddress)
263
+ print("Is the Transaction count", nonce)
264
+ let fee = estimateGasPrice * eGasReult
265
+ /*
266
+ adding
267
+ - sender address
268
+ - Gas Result
269
+ - Gas price
270
+ - amount
271
+ */
272
+ var sendTransactionIntermediateOptions = Web3Options.defaultOptions()
273
+ sendTransactionIntermediateOptions.from = senderEthAddress
274
+ sendTransactionIntermediateOptions.gasLimit = eGasReult
275
+ sendTransactionIntermediateOptions.gasPrice = estimateGasPrice
276
+
277
+ var tokenTransactionIntermediate: TransactionIntermediate!
278
+ tokenTransactionIntermediate = try wInstance.contract("Your custom contract ABI string", at: contractAddress).method("transfer", args: toaddress, amount, options: sendTransactionIntermediateOptions)
279
+
280
+ let mainTransaction = try tokenTransactionIntermediate.send(options: sendTransactionIntermediateOptions, onBlock: "latest")
281
+
282
+ print(mainTransaction.hash, "is the hash")
283
+ }
284
+ }
285
+ }
286
+ }
287
+
283
288
```
284
289
285
290
0 commit comments