Mint function keeps reverting in testing

Hey guys can anyone help me out and give me any clue of why this function keeps reverting?

function publicMint(uint256 _mintAmount) public payable {
        uint tokenId = tokenIdTracker.current();

        require(_openMint == true, "Minting is currently not open");
        require(_openPublicMint == true, "Public minting is currently not open");
        require(tokenIdTracker.current() <= max_supply, "All tokens have been minted");
        require(msg.value == publicPrice * _mintAmount, "Amount sent is incorrect");

        tokenIdTracker.increment();
        _safeMint(msg.sender, tokenId);
        _setTokenURI(
            tokenId, string(abi.encodePacked(tokenId.toString(), _baseExtension))
        );

        _wallet.transfer(msg.value);
    }

its this particular require statement that sends an error =

require(msg.value == publicPrice * _mintAmount, "Amount sent is incorrect");

The correct amount of eth is in my test wallet and all other states required are true.

1 Like

You can rewrite like this:

function publicMint(uint256 _mintAmount) public payable {
        uint tokenId = tokenIdTracker.current() + 1;//to make tokenid start from 1

        require(_openMint, "Minting is currently not open");
        require(_openPublicMint, "Public minting is currently not open");
        require(tokenIdTracker.current() <= max_supply, "All tokens have been minted");
        require(msg.value >= (publicPrice * _mintAmount), "Amount sent is incorrect");

        tokenIdTracker.increment();
        _safeMint(msg.sender, tokenId);
        _setTokenURI(
            tokenId, string(abi.encodePacked(tokenId.toString(), _baseExtension))
        );

        _wallet.transfer(msg.value);
    }
1 Like