2

I would like to to request some help in developing a mint function that restricts a public user to mint only ONE NFT with a mint price of 0 (excluding gas fees) - in the case of a promotional giveaway. Is this even possible? I would welcome any suggestions, even a supplementary centralised solution..

Here is my function so far. At the moment, the only way I can restrict the number of free minting NFT is if the owner of the contract executes the minting. But I would like the public user to execute this function, escpecially if the number of free NFTs is a lot and hence associated gas fee. Its based on the OpenZeppelin Contracts:

contract MyTestContract is ERC721, ERC721Enumerable, Ownable {

bool public preLaunchActive = false;
uint256 public maxGiveAway = 3;

function myPreLaunchGiveAway(uint amount, address to) public onlyOwner {
    require(preLaunchActive, "preLaunchActive state is not active.");
    require(amount <= maxGiveAway, "No more available.");
    require(amount > 0, "Amount must be greater than 0.");
    for (uint i = 0; i < amount; i++) {
        uint256 tokenId = totalSupply();
        if (tokenId < maxGiveAway) {
            _safeMint(to, tokenId);
        }
    }

    maxGiveAway = maxGiveAway.sub(amount);
}

}
johnDoe
  • 709
  • 11
  • 29

1 Answers1

0
require(balanceOf(msg.sender) <= maxGiveAway,"No more available.!");

Will let user mint allowed number of max give away!