当公开发售结束时,如何在 mint 函数上使用 eth_estimateGas?

发布于 2025-01-10 20:04:02 字数 607 浏览 2 评论 0原文

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 时,出现交易已还原错误,标签为“公开发售活动!”

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

Let's say I have this mint function in an ERC721 contract. How can I use eth_estimateGas on this function when saleActive is false? In other words, how can I estimate the gas limit on a transfer event before the sale is active? When I run eth_estimateGas on this function, I get a transaction reverted error, with label "Public Sale Active!"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

羁拥 2025-01-17 20:04:02

您可以分叉部署合约的网络,更改分叉网络上的值,然后估算更改后的gas。

有关使用 Ganache 创建网络分叉的示例,请参阅此答案

You can fork the network where the contract is deployed, change the value on the forked network, and then estimate the gas after the value has been changed.

See this answer for example of creating a network fork with Ganache.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文