web3swift
web3swift copied to clipboard
Send ERC-20 Token
macos 版本:12.3 xcode 版本:13.3 cocospod 版本:1.11.3 web3swift (2.6.0) and web3swift (2.3.0) I send erc-20 token without option.Value can succeed, but I fill in option.Value will report an error in the future. How to deal with it
Error reporting information: web3swift.Web3Error.processingError(desc: "Failed to fetch gas estimate")
code: @IBAction func Ethe(_ sender: Any) { SendERC(value: "1.0", toAddressString: "0xd914c8b0BD935C4F5709Bd9F1ed2A5a01ADdFE1a") }
func SendERC(value:String,toAddressString:String){
let walletAddress = EthereumAddress(address)!
let toAddress = EthereumAddress(toAddressString)!
let erc721ContractAddress = EthereumAddress("0x3aae468ffaa298147c7249ed10e03610bc932e26", ignoreChecksum: true)!
let contract = web3.contract(Web3.Utils.erc721ABI, at: erc721ContractAddress, abiVersion: 2)!
let tokenID = BigUInt(0)
let originalOwner = EthereumAddress(address)!
//print("tokenId :\(tokenID)")
let amount = Web3.Utils.parseToBigUInt(value, units: .eth)
var option = TransactionOptions.defaultOptions
option.from = walletAddress
// option.value = amount // option.gasLimit = .automatic // option.gasPrice = .automatic option.gasLimit = .manual(BigUInt(60000)) do { let gasPriceResult = try web3.eth.getGasPrice() option.gasPrice = .manual(gasPriceResult) let method = "transferFrom" let tx = contract.write(method, parameters: [originalOwner, toAddress, tokenID] as [AnyObject], extraData: Data(), transactionOptions: option)!
let result = try! tx.send(password:password)
print("scu:\(result)")
} catch let e {
print("err:\(e)")
}
}
I send erc-20 token without option Value can succeed, but I fill in option Value will report an error in the future
Success:

Can you please provide the exact code for when it is failing? The error you show is for gasLimit estimation, and I can see no reason as to why, or how, you can get that error by simply setting value for the transaction.