【问题标题】:Hardhat issue UNPREDICTABLE_GAS_LIMIT in a script within ethereum development of ERC-721在 ERC-721 的以太坊开发中的脚本中的安全帽问题 UNPREDICTABLE_GAS_LIMIT
【发布时间】:2022-02-16 17:03:58
【问题描述】:

我有一个让我非常绝望的问题,我认为这可能与“等待确认?”有关。问题,但我不知道如何激活它。

问题是,我收到了针对我的 ERC-721 合同函数的请求,该请求在部署脚本中出现以下消息:

原因:'无法估算气体;交易可能会失败或可能需要手动限制气体”, 代码:'UNPREDICTABLE_GAS_LIMIT',

我认为这可能与命令彼此快速发生有关,因为当我在 hardhad 控制台中手动执行以下步骤时(npx hardhat console --network rinkeby),一切正常工作而没有此错误(即使 .confirmations 总是 0,我不明白)

我在 deploy.js 中有以下命令 我跑:

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));
    ...
}

通过调用 await bba.getLock(0) 我得到了 错误:无法估算气体;交易可能失败或可能需要手动限制气体 (error={"name":"ProviderError","code":-32000,"_isProviderError":true}, method="call", transaction= ...

我构建了一个基于 openzeppelin 合约向导的 1:1 ERC-721 https://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,
      }
    }
  }
};

谁能指导我解决这个问题的原因?

提前致谢。

【问题讨论】:

    标签: node.js ethereum solidity hardhat erc721


    【解决方案1】:

    经过额外的研究和测试,解决方案似乎非常简单。

    我只需要为函数调用声明一个 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));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-17
      • 1970-01-01
      • 2021-07-17
      • 2018-03-15
      • 2023-03-24
      • 2021-08-20
      相关资源
      最近更新 更多