我有一个我真的很绝望的问题,我认为这可能与“等待确认?”有关。问题,但我不知道如何激活它。
问题是,我收到针对我的 ERC-721 合约函数的请求的结果,并在 部署脚本中收到以下消息:
原因:'无法估计gas;交易可能会失败或者可能需要手动限制gas', 代码:'UNPREDICTABLE_GAS_LIMIT',我认为这可能与命令彼此快速发生有关,因为当我在hardhad控制台中手动执行以下步骤时(npx Hardhat控制台--network rinkeby),一切正常,没有这个错误(即使有<>.confirmations 总是 0,我不明白)
我在deploy.js中有以下命令 我跑步时:
npx hardhat run --network rinkeby 脚本/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));
...
}
通过调用await bba.getLock(0),我得到了
错误:无法估算gas;交易可能会失败或可能需要手动气体限制(error={"name":"ProviderError","code":-32000,"_isProviderError":true}, method="call", transaction= ...
我基于openzeppelin合约向导构建了1:1 ERC-721https://docs.openzeppelin.com/contracts/4.x/wizard。
在这个合约中我添加了一个简单的功能:
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];
}
我将 INFURA 与以下 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,
}
}
}
};
任何人都可以指导我,找出该问题的原因吗?提前致谢。
我只需要为函数调用声明一个 const,然后需要对这些函数调用 wait() 调用。
正如我所读,然后该过程等待调用被挖掘。
我仍然不确定如何命令等待两次确认,但已经修复了 GAS LIMIT 问题。
const mint = await bba.safeMint("0x123...", 0, 'https://gateway.pinata.cloud/ipfs/url');
await mint.wait();
const locking= await bba.lockToken(0, "1644598343");
await locking.wait();
console.log(await bba.getLock(0));