web3swift
web3swift copied to clipboard
Call Custom contract address fuction
What context is your feature request related to?
I created contract address for extra features for transfer NFT Here is the logic for it: step1: User can request for the NFT to Admin person (request only goes if user eligible) step2: Requested NFT automatically transfer to that user on his/her wallet
My function name is callNFT with parameters Timestamp, NFTId, Amount of NFT, V, R , S
I did try call this function but didt work [NOTE: i change fuction details and function name due to security ]
let abiContract = self.getDepositABIContract(completion: { abiJson in
let value: String = "0" // Any amount of Ether you need to send
let walletAddress = EthereumAddress(wallet.address)! // Your wallet address
let contractMethod = "approveAndCall" // Contract method you want to write
let contractABI = abiJson
let contractAddress = EthereumAddress(AppDataModelManager.shared.getNetworkStatus().getDepositTokenAddress())!
let abiVersion = 2 // Contract ABI version
let parameters: [Any] = [walletAddress, UInt64(amountString) ?? 0,toAddress] // Parameters for contract method
let extraData: Data = Data() // Extra data for contract method
let contract = web3.contract(contractABI ?? "", at: contractAddress, abiVersion: abiVersion)!
var options = TransactionOptions.defaultOptions
options.value = Web3.Utils.parseToBigUInt(value, units: .eth)
options.from = walletAddress
options.gasPrice = .automatic
options.gasLimit = .automatic
let txMessage = contract.write(
contractMethod,
parameters: parameters as [AnyObject],
extraData: extraData,
transactionOptions: options)!
DispatchQueue.global(qos: .userInitiated).async {
do {
try txMessage.call()
} catch let error as NSError {
print("Failed to load: \(error.localizedDescription)")
}
}
})
What solution would you like?
I want to call custom function of the smart contract that i created on solidity
Any additional context?
No response
check your Contract ABI , for reference check other ABI how it is written inside this library