Failed to fetch gas estimate when sending erc20
See original GitHub issueTrying to send an erc20 token but getting a Web3Error “Failed to fetch gas estimate”. Here is a snippet of my code:
let amount = Web3.Utils.parseToBigUInt(tokenAmount, units: .eth)
var options = TransactionOptions.defaultOptions
options.gasPrice = gasPrice // is calculated as follows web3Main.eth.getGasPrice()
options.gasLimit = gasLimit //set to BigUInt(50000)
options.from = EthereumAddress(from)
options.to = ethToAddress
options.value = amount
guard let myTransaction = contract.method("transfer", parameters: [ethToAddress, amount] as [AnyObject], extraData: Data(), transactionOptions: options) else {
throw Web3Error.transactionSerializationError
}
let myRes = try myTransaction.send(password: "PASSWORD", transactionOptions: options)
Produces error on the last line. Any ideas?
Issue Analytics
- State:
- Created 4 years ago
- Comments:17 (4 by maintainers)
Top Results From Across the Web
Failed to fetch gas estimate when sending erc20 #147 - GitHub
Trying to send an erc20 token but getting a Web3Error "Failed to fetch gas estimate". Here is a snippet of my code: let...
Read more >Why did my transaction fail with an "Out of Gas" error? How ...
Cause. The "out of gas" error occurs when all the gas you allotted for the transaction is consumed before the transaction could complete....
Read more >How to fix "Gas estimation failed error" when transferring ...
I have a simple ERC20 contract which is ERC20Detailed, ERC20Mintable and Ownable. On deployment I want: Add Minter to a new account, ...
Read more >Changelog - CocoaPods
Error in Documentation Examples: "Failed to fetch gas estimate" #421; BSC Network Transaction #418; How to sign and send ERC20 token #413; Example...
Read more >Solidity/Web3 Error : We were not able to estimate gas. There ...
Solidity/Web3 Error : We were not able to estimate gas. There might be an error in the contract and this transaction may fail....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The problem here is when sending ERC20 tokens the
options.value
field should not be set. That field is supposed to be used for sending ETH. Notice the amount is already specified in theparameters
array. So just delete the lineoptions.value = amount
.This should probably be fixed in the example in the documentation as that sets the
options.value
field which will always result in this error.Please fix it in document for everyone! thanks