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.

Ethers still tries to estimate gas even when passing manual gasLimit

See original GitHub issue

Describe the bug I’m trying to call a contract method with an unpredictable gas limit, however if I try to call it and pass the gasLimit manually I get get a “Error: cannot estimate gas; transaction may fail or may require manual gas limit” error.

Maybe I’m missing something but shouldn’t ethers skip estimating gas if it’s passed manually?

Reproduction steps You can test with the following contract in rinkeby:

const CONTRACT = "0x10539a06b047259f247f8c622430c22803821A00";
const ABI = [
  'function stakeOf(address _owner) public view returns (uint256[] memory)'
];

// using JsonRpcProvider as an example, but I've tried with metamask as well and same issue
const provider =new ethers.providers.JsonRpcProvider(
    "provider URL"
);
const signer = provider.getSigner();
const contract = new ethers.Contract(CONTRACT, ABI, signer);

contract.stakeOf("0x73257cE508dBB94Ff78C27381FddD42FB7266Ba4", {
  gasLimit: '50000000',
}),

Result

Error: cannot estimate gas; transaction may fail or may require manual gas limit (error={"name":"ProviderError","code":3,"_isProviderError":true,"data":"0x4e487b710000000000000000000000000000000000000000000000000000000000000032"}, method="call", transaction={"from":"0x73257cE508dBB94Ff78C27381FddD42FB7266Ba4","gasLimit":{"type":"BigNumber","hex":"0x02faf080"},"to":"0x10539a06b047259f247f8c622430c22803821A00","data":"0x4262336000000000000000000000000073257ce508dbb94ff78c27381fddd42fb7266ba4","accessList":null}, code=UNPREDICTABLE_GAS_LIMIT, version=providers/5.5.1)
    //...
  method: 'call',
  transaction: {
    from: '0x73257cE508dBB94Ff78C27381FddD42FB7266Ba4',
    gasLimit: BigNumber { value: "50000000" },
    to: '0x10539a06b047259f247f8c622430c22803821A00',
    data: '0x4262336000000000000000000000000073257ce508dbb94ff78c27381fddd42fb7266ba4',
    accessList: null
  }
}

Environment: Node: v14.17.4

This happens in both node and browser environments.

Search Terms gas limit, estimate gas

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
ricmoocommented, Mar 30, 2022

@nataouze I’ve added context to discussion #2849 to help explain what is going on and will be keeping that up to date if you want to hop over there. 😃

0reactions
nedgarcommented, Sep 18, 2022

Thanks for the fix @ricmoo. I’ve (finally) verified it – see https://github.com/NomicFoundation/hardhat/issues/2248#issuecomment-1250350108

Read more comments on GitHub >

github_iconTop Results From Across the Web

transaction may fail or may require manual gas limit ...
Error: cannot estimate gas; transaction may fail or may require manual gas limit. This error is because the transaction was not complete and ......
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 >
hardhat cannot estimate gas; transaction may fail or ... - You.com
I am trying to transfer tokens from a contract deployed on the blockchain, ... Error cannot estimate gas; transaction may fail or may...
Read more >
Documentation - Ethers.js
gasLimit - the amount of gas (theoretically) to allow a node to use during the execution of the code; since there is no...
Read more >
How to re-send a transaction with higher gas price using ...
1. Sometimes, you submit a transaction on Ethereum without enough gas due to network congestion or too m... 2. We do a transaction...
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