当公开发售结束时,如何在 mint 函数上使用 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;
}
假设我在 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以分叉部署合约的网络,更改分叉网络上的值,然后估算更改后的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.