question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issue with Cannot Estimate Gas Error

See original GitHub issue

Ethers Version

5.4.7

Search Terms

No response

Describe the Problem

Apologize that there isn’t a better category for opening this question/issue:

I wanted to know why I need to provide gas price or gas limit overrides for an external/view contract function if they don’t require gas and are not being performed inside another transaction? And, no other processing is occurring in the function but returning contract state variables.

function getDetails() external view returns ( uint256, uint256, uint256, address, uint256 )

I encountered the “cannot estimate gas; transaction may fail or may require manual gas limit” error originally. It also required that I use a signer and not just a provider when creating the contract instance.

To make it worse, once I switched to a signer, and provided those overrides

const overrides = { gasPrice: ethers.utils.parseUnits(“50000000000”, “wei”), gasLimit: ethers.utils.parseUnits(“100000000000”, “wei”) };

const response = await contract.getDetails(overrides);

I receive an insufficient funds error (Rinkeby) when I have .6 ETH on the account:

Error: insufficient funds for intrinsic transaction cost [ See: https://links.ethers.org/v5-errors-INSUFFICIENT_FUNDS ] (error={“code”:-32000,“message”:“err: insufficient funds for gas * price + value: address 0xc0Eb169794B18685a67C0a998292D184Ddeaeba3 have 600000000000000000 want 200000000000000000000000 (supplied gas 500000000)”}, method=“call”, transaction={“from”:“0xc0Eb169794B18685a67C0a998292D184Ddeaeba3”,“gasLimit”:{“type”:“BigNumber”,“hex”:“0x058d15e176280000”},“gasPrice”:{“type”:“BigNumber”,“hex”:“0x016bcc41e90000”},“to”:“0x5FbDB2315678afecb367f032d93F642f64180aa3”,“data”:“0x936afab3”,“accessList”:null}, code=INSUFFICIENT_FUNDS, version=providers/5.4.5)

Code Snippet

const overrides = {
            gasPrice: ethers.utils.parseUnits("50000000000", "wei"),
            gasLimit: ethers.utils.parseUnits("100000000000", "wei")
};

const response = await contract.getDetails(overrides);

Contract ABI

No response

Errors

Error: insufficient funds for intrinsic transaction cost [ See: https://links.ethers.org/v5-errors-INSUFFICIENT_FUNDS ] (error={"code":-32000,"message":"err: insufficient funds for gas * price + value: address 0xc0Eb169794B18685a67C0a998292D184Ddeaeba3 have 600000000000000000 want 200000000000000000000000 (supplied gas 500000000)"}, method="call", transaction={"from":"0xc0Eb169794B18685a67C0a998292D184Ddeaeba3","gasLimit":{"type":"BigNumber","hex":"0x058d15e176280000"},"gasPrice":{"type":"BigNumber","hex":"0x016bcc41e90000"},"to":"0x5FbDB2315678afecb367f032d93F642f64180aa3","data":"0x936afab3","accessList":null}, code=INSUFFICIENT_FUNDS, version=providers/5.4.5)

Environment

Hardhat

Environment (Other)

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:14 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
hyndsitecommented, Jun 29, 2022

Yep. Thanks @ricmoo

1reaction
hyndsitecommented, Jun 28, 2022

Thanks @bobanm for the help and the honest feedback.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Fix "cannot estimate gas" on PancakeSwap
“cannot estimate gas” on PancakeSwap means that the exchange cannot estimate the fee ...
Read more >
Error: cannot estimate gas; transaction may fail or may require ...
The only solution is to set {gasLimit: 3e7} in each contract function call. One thing that can trigger this problem is when the...
Read more >
transaction may fail or may require manual gas limit" : r/ethdev
The most likely reason for this error is that you are using "string" data type for URIs, and so the compiler naturally cannot...
Read more >
How to Fix “Cannot Estimate Gas” Pancakeswap Error
The “Cannot Estimate Gas” error basically means that the platform can't estimate the fees associated with a transaction.
Read more >
How to Fix 'Cannot Estimate Gas' Error on PancakeSwap ...
This error message means what it says: The swap platform simply cannot estimate the gas fees for that particular transaction. This error occurs ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found