Skip to content

Ethers still tries to estimate gas even when passing manual gasLimit #2603

Closed
@ricmoo

Description

@ricmoo

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or improvement.fixed/completeThis Bug is fixed or Enhancement is complete and published.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions