Troubleshooting: "UNPREDICTABLE_GAS_LIMIT" thrown when calling a readonly contract method.
foxgem
Posted on January 3, 2023
Symptom
When a calling to a smart contract readonly method happened, a "UNPREDICTABLE_GAS_LIMIT" exception was thrown:
ERROR Error: Uncaught (in promise): Error: cannot estimate gas; transaction may fail or may require manual gas limit (error={"code":-32000,"message":"execution reverted"}, method="call", transaction={"to":"0xE6183d3094b9r360B121Ec1330afAE76A74d1cbF","data":"0xdb699765000000000000000000000000b2b7bedd7d7fc19804c7dd4a4e8174c4c73c220d0000000000000000000000000000000000000000000000000de0b6b3b7640000000000000000000000000000000000000000000000000000000000006c915aef"}, code=UNPREDICTABLE_GAS_LIMIT, version=providers/5.0.24)
at d.makeError (main.a577643548eb15e6832e.js:1)
at d.throwError (main.a577643548eb15e6832e.js:1)
at Z (main.a577643548eb15e6832e.js:1)
at $e.<anonymous> (main.a577643548eb15e6832e.js:1)
at Generator.throw (<anonymous>)
at a (main.a577643548eb15e6832e.js:1)
at l.invoke (polyfills.797d13e303959ed8dd77.js:1)
at Object.onInvoke (main.a577643548eb15e6832e.js:1)
at l.invoke (polyfills.797d13e303959ed8dd77.js:1)
at a.run (polyfills.797d13e303959ed8dd77.js:1)
at Z (polyfills.797d13e303959ed8dd77.js:1)
at polyfills.797d13e303959ed8dd77.js:1
at a (main.a577643548eb15e6832e.js:1)
at l.invoke (polyfills.797d13e303959ed8dd77.js:1)
at Object.onInvoke (main.a577643548eb15e6832e.js:1)
at l.invoke (polyfills.797d13e303959ed8dd77.js:1)
at a.run (polyfills.797d13e303959ed8dd77.js:1)
at polyfills.797d13e303959ed8dd77.js:1
at l.invokeTask (polyfills.797d13e303959ed8dd77.js:1)
at Object.onInvokeTask (main.a577643548eb15e6832e.js:1)
NOTE
It is READONLY here.
Cause
If we are calling a write method and get this error, that's understandable. However, for a readonly method invocation, no transaction will be sent, so no gas limit estimation should happen at all!
In this case, it is highly probable that you are calling a non existent method in the contract. Especially, it is not uncommon when you are using "human readable abi" with ethers.js, such as a typo.
Solution
So, to solve this, you can check if the target contract includes the method you are calling:
- wrong method names?
- wrong method arguments?
- wrong abis? Note, when you are using "human readable abi", please make sure the punctuation is not included. Fox example:
- √:
function testMethod(uint256) public view returns (uint256)
- X:
function testMethod(uint256) public view returns (uint256);
- √:
The only difference between these two abis is the ";" at the end.
Posted on January 3, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
January 3, 2023