如图,调用合约,报这个错:
插代码:
/**
* @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);
}
问题出在这里: require(msg.value == getPrice(1), "Value needs to be exactly the mint fee!");
经过研究比较,发现是msg.value传大了,【说明,用的是测试网,测试网和主网的参数不一样,现在测试币不好弄,所以分别设置的,测试网地址:https://goerli.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161】
下面是web3调用代码:
const func = await depositContract.mintTo(account, {
value: web3.utils.toWei('0.01','ether'),
gasLimit: DEFAULT_GAS_LIMIT,
});
调用核心代码就这些,完成了一个nft测试网mint的调用。