-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UNPREDICTABLE_GAS_LIMIT #2248
Comments
While it's good for us to know when such errors are happening in the wild, there's little we can do about it with just an error message. Can you provide more information? Specifically, it would be ideal if you could provide your hardhat project (including all relevant files and folders). At the very least, we would need some instructions on how to reproduce the problem you are seeing. |
my contract content:
my handhat.config.js content:
my test.js content:
|
cmd: |
@HakunamatataLeo That's progress, but we're still not at a reproduction scenario yet. This gives us some more hints, but without complete copies of the contracts used in your test, we cannot possibly reproduce the issue, and without reproducing an issue we cannot fix it. |
I'm having the same error but not while deploying on forked Mainnet but while deploying on Ropsten network! Edit: Solved the issue by adding
|
This is happening to me while deploying to the goerli network, adding gas doesn't fix it for me |
@toshiSat can you provide a reproduction scenario? |
I figured my issue out. It didn't like approve infinite in the constructor. Once I put those in an initialize functions, the deployments worked |
Closing this for lack of reproduction steps. |
I'm seeing this with To reproduce, call I'll log this to an open discussion item for ethers: ethers-io/ethers.js#2602 |
I've added a standalone example there.
|
Thanks for the detailed info @nedgar. So this looks like an ethers.js thing? If not and if you think there's something we can do on our side, please let us know. |
Hi @fvictorio. It's actually a combination of both HardHat and ethers.js. I've been unable to reproduce it using ethers.js on its own. But it's code in ethers.js's Here is a standalone example (simplified further from the one here: ethers-io/ethers.js#2602 (comment)). // const { ethers } = require("ethers");
const {
CONTRACT_ADDRESS = "0x198478f870d97d62d640368d111b979d7ca3c38f", // https://opensea.io/collection/8sian-main-collection (on Ethereum)
INFURA_KEY,
PRIVATE_KEY
} = process.env;
const ABI = [
"function ownerOf(uint256 id) view returns (address)",
];
async function main() {
// use HardHat config
const [signer] = await ethers.getSigners();
const { provider } = signer;
// use plain Ethers.js
// const provider = new ethers.providers.JsonRpcProvider("https://mainnet.infura.io/v3/" + INFURA_KEY);
// const signer = new ethers.Wallet(PRIVATE_KEY, provider);
// works with plain Ethers.js, but fails with "cannot estimate gas"... with HardHat
const contract = new ethers.Contract(CONTRACT_ADDRESS, ABI, provider /* or signer */);
// expectation:
// id 0 should throw an error with code CALL_EXCEPTION and reason "ERC721: owner query for nonexistent token",
// ids 1 to 8888 should return its owner's address
const id = 0;
const owner = await contract.ownerOf(id, { gasLimit: 100000 }); // giving gasLimit makes no difference
console.log("Owner is:", owner);
}
main()
.then(() => {
console.log("Completed normally.");
process.exit();
})
.catch((err) => {
console.log("Error!", err);
process.exit(1);
}); When run using hardhat, it fails with the
but note that the nested When the
Note that the error here is |
My require("@nomiclabs/hardhat-ethers");
// require("dotenv").config();
const { INFURA_KEY, PRIVATE_KEY } = process.env;
/**
* @type import('hardhat/config').HardhatUserConfig
*/
module.exports = {
solidity: {
version: "0.8.12",
},
},
networks: {
mainnet: {
chainId: 1,
url: "https://mainnet.infura.io/v3/" + INFURA_KEY,
accounts: [PRIVATE_KEY],
},
},
}; |
It can be reproduced with any ERC-721 contract, when the token ID does not exist, assuming the contract's |
I added the following at the top of JsonRpcProvider's checkError, in the local compiled JS code at console.log("checkError:", {method, error: {message: error.message, ...error}, params}); (the funkiness for Running my example above with the ethers config, it yields:
so the first With the hardhat config, it yields:
so it ends up at that special case for |
Thanks a lot @nedgar, this is really useful |
I've put this in a standalone repo: https://github.com/nedgar/ethers-hardhat-error-handling-issue |
Do we have an update where this error is coming from already? |
@pheuberger At the time of filing this, the string was coming from this line in JsonRpcProvider: logger.throwError("cannot estimate gas; transaction may fail or may require manual gas limit", Logger.errors.UNPREDICTABLE_GAS_LIMIT, { It's possible it has been fixed by this commit, fixing ethers-io/ethers.js#2603, but I have not had a chance to verify that. |
See comment above for context. |
Thanks a lot @nedgar! Seems I glanced over the comments a little too quickly and missed that you already pointed out what the cause is. I'll update ethers and see if the error shows up again. |
Hey guys, is this issue being worked on? I have the same problem when connecting to private network (hyperledger besu). I never get any original revert message, always:
|
@rejnowskimikolaj Are you calling |
@nedgar this is done implicitly, before commiting the transaction. OFC I've checked the nested errors. There are no revert messages, only those general "UNPREDICTABLE_GAS_LIMIT" errors. |
this is my package.json:
|
also, I've tried to debug it the same way you did here, and still there is no revert message.
|
This issue was marked as stale because it didn't have any activity in the last 30 days. If you think it's still relevant, please leave a comment indicating so. Otherwise, it will be closed in 7 days. |
I am having the same problem, for some reason I can sign transactions with one account but when I switch accounts it cannot predict gas anymore. What I am using: local hardhat node running, I can sign transactions with the account I deployed the smart contract however I cannot sign transactions with other test accounts. If anyone else got the same issue we could discuss why this is happening |
If you are using MetaMask: Settings/Advanced/Reset Account and then try again. |
hello, any updates on this issue? |
I have solved the problem I was working on. An unpredictable gas limit message can be really misleading sometimes. In general, an unpredictable gas limit message is due to you trying to use a function that has some other bits and quirks you need to consider that you miss. At least this was my case :D. So, if anyone still having this issue, take a step back and go over what should happen in the code and what is happening and question whether you understand it fully. |
Sorry for the delay in verifying the fix. I can confirm that as of ethers.js 5.6.2, my scenario above of issuing a call to a view function (which shouldn't have to estimate gas to begin with) now fails with a Using the standalone example of calling an ERC-721 contract's
|
Since the original problem report was so ambiguous, I suggest treating this issue as "UNPREDICTABLE_GAS_LIMIT when calling a view function" and closing it as fixed. |
Hi, I had the same problem mentioned that does not return correct error and always: My solution is that, we have the returned error: then we can try to refer to: I wrote such a function that helps me with this: I expect that this will help you ! |
Hi everyone, I'm revisiting this issue after a long time, and this is what I found using the latest version of ethers:
I'm going to close this now. If someone has some issue around this, please open a new issue with minimal reproduction steps. |
Error: cannot estimate gas; transaction may fail or may require manual gas limit (error={"name":"ProviderError","code":-32000,"_isProviderError":true,"data":"null"}, method="call", transaction={"from":“0x3c82D4291cF4bAeADb7e5E05f5cB0c0xxxxxxxx","to":"0x3c82D4291cF4bAeADb7e5E05f5cB0xxxxxxxxx","data":"0x6352211e0000000000000000000000000000000000000000000000000000000000000001","accessList":null}, code=UNPREDICTABLE_GAS_LIMIT, version=providers/5.5.1)
The text was updated successfully, but these errors were encountered: