'How can I use eth_estimateGas on a mint function when the public sale is closed?

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!"



Solution 1:[1]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Petr Hejda