I have a problem that I really despair of and I think it has maybe to do with an "wait for confirmation?" issue, but I don't know how to activate this.
Issue is, that I get as result of an request against a function of my ERC-721 contract following message in a deployment script:
reason: 'cannot estimate gas; transaction may fail or may require manual gas limit', code: 'UNPREDICTABLE_GAS_LIMIT',
I think it maybe has to do with that the commands are happening to fast after each other because, when I proceed the following steps in a hardhad console manually (npx hardhat console --network rinkeby), everthing works without this error (even with that <>.confirmations are always 0, what I don't understand)
I have the following commands in a deploy.js I run with:
npx hardhat run --network rinkeby scripts/deploy.js
async function main() {
const BBA = await hre.ethers.getContractFactory("mycontract");
const bba = await BBA.deploy();
await bba.deployed();
console.log("mycontract deployed to:", bba.address);
await bba.safeMint("0x123...", 0, 'https://gateway.pinata.cloud/ipfs/url');
await bba.lockToken(0, "1644598343");
console.log(await bba.getLock(0));
...
}
With the call await bba.getLock(0) I get the Error: cannot estimate gas; transaction may fail or may require manual gas limit (error={"name":"ProviderError","code":-32000,"_isProviderError":true}, method="call", transaction= ...
I build a 1:1 ERC-721 based on openzeppelin contract wizard https://docs.openzeppelin.com/contracts/4.x/wizard.
In this contract I added a simple function:
mapping(uint256 => uint256) private _locks;
function lockToken(
uint256 targetTokenId,
uint256 since,
) public {
_locks[targetTokenId] = since;
}
function getLock(uint256 targetTokenId) public view returns (uint256) {
return _locks[targetTokenId];
}
I use INFURA with following hardhat.config.js:
const { projectId, mnemonic } = require('./secrets.json');
module.exports = {
rinkeby: {
url: "https://rinkeby.infura.io/v3/" + projectId,
accounts: { mnemonic: mnemonic },
confirmations: 2,
gas: 2100000,
gasPrice: 8000000000,
saveDeployments: true
}
},
solidity: {
version: "0.8.4",
settings: {
evmVersion: "byzantium",
optimizer: {
enabled: true,
runs: 1500,
}
}
}
};
Anyone could guide me, to the reason of that problem?
Thanks in advance.