【问题标题】:How can I use eth_estimateGas on a mint function when the public sale is closed?公开发售结束后,如何在铸币功能上使用 eth_estimateGas?
【发布时间】:2022-07-08 03:02:00
【问题描述】:
function mint(uint256 addr, uint256 id) public payable {
    require(id < 10000000000, "id invalid");
    require(saleActive == true, "Public Sale not active!");
    require(msg.value >= mintPrice, "No enough Eth supplied!");
    require(availableSupply > 0, "Not enough supply of tokens"); 

    _safeMint(msg.sender, currentID.current());
    currentID.increment();
    availableSupply = availableSupply - 1;
  }

假设我在 ERC721 合约中有这个铸币厂功能。当 saleActive 为 false 时,如何在此函数上使用 eth_estimateGas?换句话说,在销售活动开始之前,我如何估计转移事件的 gas 限制?当我在这个函数上运行 eth_estimateGas 时,我收到一个交易恢复错误,标签为“Public Sale Active!”

【问题讨论】:

    标签: javascript ethereum smartcontracts web3js nft


    【解决方案1】:

    你可以对部署合约的网络进行分叉,在分叉的网络上更改值,然后在更改值后估算gas。

    请参阅this answer,例如使用 Ganache 创建网络分叉。

    【讨论】:

    • 我是否必须在网络分叉上部署合约才能做到这一点?
    • @DanielZafman 仅当它尚未部署在源网络上时。
    猜你喜欢
    • 1970-01-01
    • 2022-07-24
    • 2021-11-24
    • 2022-07-21
    • 2021-12-22
    • 2019-12-11
    • 2020-10-12
    • 2022-12-10
    • 2012-04-19
    相关资源
    最近更新 更多