Closed
Description
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