Fail with error ‘Value needs to be exactly the mint fee!‘

As shown in the figure, call the contract and report this error:

Insert code:

    /**
    * @dev Mints a single token to an address.
    * fee may or may not be required*
    * @param _to address of the future owner of the token
    */
    function mintTo(address _to) public payable {
        require(onlyERC20MintingMode == false, "Only minting with ERC-20 tokens is enabled.");
        require(getNextTokenId() <= collectionSize, "Cannot mint over supply cap of 1000");
        require(mintingOpen == true && onlyAllowlistMode == false, "Public minting is not open right now!");
        
        require(canMintAmount(_to, 1), "Wallet address is over the maximum allowed mints");
        require(msg.value == getPrice(1), "Value needs to be exactly the mint fee!");
        
        _safeMint(_to, 1, false);
    }

The problem is here: require(msg.value == getPrice(1), "Value needs to be exactly the mint fee!");

After research and comparison, it was found that the msg.value was too large. [Explanation, the test network is used. The parameters of the test network and the main network are different. Now the test currency is not easy to get, so they are set separately. The test network address: https : //goerli.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161

The following is the web3 calling code:

        const func = await depositContract.mintTo(account, {
          value: web3.utils.toWei('0.01','ether'),
          gasLimit: DEFAULT_GAS_LIMIT,
      });

That's all for calling the core code, and completed a call to the nft test network mint.

Guess you like

Origin blog.csdn.net/chhpearl/article/details/128791538