This function maxMintAmountPerWallet is not working, Trying to prevent people from minting more then 2 tokens on the free mint phase.
Thank you in advance.
contract DD is ERC721A, Ownable, ReentrancyGuard {
using Strings for uint256;
string public uriPrefix = '';
string public uriSuffix = '.json';
uint256 public cost;
uint256 public freeMintSupply = 2;
uint256 public maxSupply;
uint256 public maxMintAmountPerWallet = 3;
mapping(address => uint256) private _walletMints;
mapping(address => uint256) private _freeWalletMints;
bool public paused = true;
constructor(
string memory _tokenName,
string memory _tokenSymbol,
uint256 _cost,
uint256 _maxSupply
) ERC721A(_tokenName, _tokenSymbol) {
setCost(_cost);
maxSupply = _maxSupply;
_safeMint(_msgSender(), 10);
}
modifier mintCompliance(uint256 _mintAmount) {
require(_mintAmount > 0 && _walletMints[_msgSender()] + _mintAmount < maxMintAmountPerWallet + 1, 'Invalid mint amount!');
require(totalSupply() + _mintAmount <= maxSupply, 'Max supply exceeded!');
require(totalSupply() >= freeMintSupply, 'Free mint not finished yet!');
_;
}
modifier freeMintCompliance(uint256 _mintAmount) {
require(_mintAmount > 0 && _mintAmount <= 1, 'You can mint only One!');
require(_freeWalletMints[_msgSender()] + _mintAmount <= 1, 'You have already minted');
require(totalSupply() + _mintAmount <= freeMintSupply, 'Max free mint supply exceeded!');
_;
}
modifier mintPriceCompliance(uint256 _mintAmount) {
require(msg.value >= cost * _mintAmount, 'Insufficient funds!');
_;
}
function freeMint(uint256 _mintAmount) public payable freeMintCompliance(_mintAmount) {
require(!paused, 'The contract is paused!');
_freeWalletMints[_msgSender()] += _mintAmount;
_safeMint(_msgSender(), _mintAmount);
}
function mint(uint256 _mintAmount) public payable mintCompliance(_mintAmount) mintPriceCompliance(_mintAmount) {
require(!paused, 'The contract is paused!');
_walletMints[_msgSender()] += _mintAmount;
_safeMint(_msgSender(), _mintAmount);
}
function mintForAddress(uint256 _mintAmount, address _receiver) public onlyOwner {
require(_mintAmount > 0, 'Invalid mint amount!');
_safeMint(_receiver, _mintAmount);
}
function _startTokenId() internal view virtual override returns (uint256) {
return 1;
}
function tokenURI(uint256 _tokenId) public view virtual override returns (string memory) {
require(_exists(_tokenId), 'ERC721Metadata: URI query for nonexistent token');
string memory currentBaseURI = _baseURI();
return bytes(currentBaseURI).length > 0
? string(abi.encodePacked(currentBaseURI, _tokenId.toString(), uriSuffix))
: '';
}
function setCost(uint256 _cost) public onlyOwner {
cost = _cost;
}
function setUriPrefix(string memory _uriPrefix) public onlyOwner {
uriPrefix = _uriPrefix;
}
function setUriSuffix(string memory _uriSuffix) public onlyOwner {
uriSuffix = _uriSuffix;
}
function setPaused(bool _state) public onlyOwner {
paused = _state;
}
function setFreeMint(uint256 _supply) public onlyOwner {
freeMintSupply = _supply;
}
function setMaxMintAmountPerWallet(uint256 _maxMintAmountPerWallet) public onlyOwner {
maxMintAmountPerWallet = _maxMintAmountPerWallet;
}
function withdraw() public onlyOwner nonReentrant {
(bool os, ) = payable(owner()).call{value: address(this).balance}('');
require(os);
}
function _baseURI() internal view virtual override returns (string memory) {
return uriPrefix;
}
}