Gas estimation failure gives a misleading error message
See original GitHub issueLaunching a transaction to the Goerli network, I have been getting this error:
{
"reason":"cannot estimate gas; transaction may fail or may require manual gas limit",
"code":"UNPREDICTABLE_GAS_LIMIT",
"error":{
"reason":"processing response error","code":"SERVER_ERROR",
"body":"{\"jsonrpc\":\"2.0\",\"id\":69,\"error\":{\"code\":-32000,\"message\":\"gas required exceeds allowance (0)\"}}","error":{"code":-32000},"requestBody":"{\"method\":\"eth_estimateGas\",\"params\":[{\"gasPrice\":\"0xb2d05e00\",\"from\":\"0xe101391adf348cd80bb71b97306f3cddd5d34586\",\"to\":\"0x1a72d4949936bda05e187706daf0db6fb96603b6\",\"data\":....}
The transaction is launched like:
const contract = new Contract(addr, abi, wallet)
const tx = await contract.myTransaction(...)
At first I checked https://github.com/ethers-io/ethers.js/issues/484 as a potential duplicate. However, the real error is that the account sending the transaction holds no ether. Nothing related to failing transactions or similar.
In such cases, it would be nice to detect the insufficient or null balance and warn about this instead of the unpredictable gas limit message alone. BTW, thank you for such a great library!
Issue Analytics
- State:
- Created 3 years ago
- Reactions:8
- Comments:18 (2 by maintainers)
Top Results From Across the Web
Gas estimation failure gives a misleading error message #1944
Makes an estimate gas rpcall to the node. If call reverts you will get error cannot estimate gas that you are getting. (I...
Read more >Gas Estimation Failed idk why - Ethereum Stack Exchange
First, check if your transaction's setup(gas/gas limit) is ok (see this). If everything is okay, the most probable issue might be the size ......
Read more >We were not able to estimate gas. There might be an error in ...
"We were not able to estimate gas. There might be an error in the contract and this transaction may fail." It gives me...
Read more >transaction may fail or may require manual gas limit" : r/ethdev
I am trying a mint function that I wrote and getting this error: Error: cannot estimate gas; transaction may fail or may require...
Read more >Gas estimation errored with the following message (see below ...
I deployed the same code on fuji and it is working fine. · Wow, it really did deploy.
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
I’ve done further debugging in regards to this issue. I think the main problem is that Ethers includes a
gasPrice
parameter when estimating gas. I’ve added some of the Eth JSON RPC requests done via both Ethers.js and Web3.js as examples.For Ethers.js, when estimating the gas for a contract method:
Even though the from account has plenty of funds (testing account) the UNPREDICTABLE GAS LIMIT happened. For the same transaction using the web3.js library the
gasPrice
is not included (andfrom
is not included as well) and so it works:Hope this helps. Probably simplifying the
eth_estimateGas
method to not includegasPrice
should solve this.@zemse As I was saying, the transaction and the contract were both correct. Submitting the very same parameters with Remix (from the right wallet) worked flawlessly. And also, submitting the very same transaction with the right wallet from Ethers.js also worked flawlessly, then.
So:
It may be a vicious circle, because you can’t know if you have enough ether for a transaction until you have estimated it. And you can’t estimate as estimation fails because you have insufficient funds.
But at least, if the balance is exactly 0, we do know for sure that the failure to estimate is due to this.
Thank you!