We are creating an ERC-721 token that does through the standard minting procedure. I'm looking for a the most gas efficient way to adjust the price to a tiered system. We want the price to increase every 2000 minted.

Forgive me, I'm new to solidity and gas considerations. Please make your answer beginner friendly.

Here's my mint function:

function mintNFT(uint256 _count) public payable {
        uint256 totalSupply = totalSupply();

        require(isSaleActive, "Sale is not active" );
        require(_count > 0 && _count < MAX_TOKENS_PER_PURCHASE + 1, "Exceeds maximum tokens you can purchase in a single transaction");
        require(totalSupply + _count < MAX_TOKENS + 1, "Exceeds available NFTs");
        require(msg.value >= price * _count, "Ether value sent is not correct");
        for(uint256 i = 0; i < _count; i++){
                _safeMint(msg.sender, totalSupply + i);

1 Answer 1


You can simply do this (Explained in comments if it is needed):

//Declare a variable to counter mint
uint256 mintCounter;

//I write the part you want, it is not all
function mintNFT(uint256 _count) public payable{
  mintCounter ++;
  //Part below needs some fixation
  require(msg.value >= price * (1 + (mintCount / 2000)), "Ether value sent is not correct");

That is it. If minCount is 1999, (mintCount / 2000) will be 0 so first 1999 mints will cost just 1x price

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.