Hello,
I'm testing a solidity contract ... but I'm having a problem calling the mint method from the frontend.
Contract is deployed here: https://rinkeby.etherscan.io/address/0x86C31eA7a0D8996db3cB9da52F3386DA6029a387#code
Mint method
uint256 public constant MINT_PRICE = 0.00420 ether;
function mintTo(address recipient) public payable returns (uint256) {
uint256 tokenId = currentTokenId.current();
require(tokenId < TOTAL_SUPPLY, "Max supply reached");
require(msg.value == MINT_PRICE, "Transaction value did not equal the mint price");
currentTokenId.increment();
uint256 newItemId = currentTokenId.current();
_safeMint(recipient, newItemId);
return newItemId;
}
Frontend code
const provider = new ethers.providers.Web3Provider(ethereum)
const signer = provider.getSigner()
const nftContract = new ethers.Contract(
nftContractAddress,
NFT.abi,
signer
)
const options = { value: ethers.utils.parseEther("0.00420") }
let nftTx = await nftContract.mintTo(currentAccount, options)
The error
Error minting NFT Error: non-payable method cannot override value (operation="overrides.value", value={"type":"BigNumber","hex":"0x0eebe0b40e8000"}, code=UNSUPPORTED_OPERATION, version=contracts/5.6.2)
at Logger.makeError (index.ts:261:1)
at Logger.throwError (index.ts:273:1)
at index.ts:268:1
at Generator.next (<anonymous>)
at fulfilled (index.ts:1:1)
I also have a hardhat task that works. It looks like this:
task("mint", "Mints from the NFT contract")
.addParam("address", "The address to receive a token")
.setAction(async function (taskArguments, hre) {
const contract = await getContract("NFT", hre);
const transactionResponse = await contract.mintTo(taskArguments.address, {
gasLimit: 500_000,
value: ethers.utils.parseEther("0.00420")
});
console.log(`Transaction Hash: ${transactionResponse.hash}`);
});
I tried adding just the gasLimit
in the options
Error with gasLimit
:
Error minting NFT Error: transaction failed [ See: https://links.ethers.org/v5-errors-CALL_EXCEPTION ] (transactionHash="0x64111e3f81675202c90a2aaf5a520c573ed2ff82544d4f76bba3ffc73b2d05a5", transaction={"hash":"0x64111e3f81675202c90a2aaf5a520c573ed2ff82544d4f76bba3ffc73b2d05a5","type":2,"accessList":null,"blockHash":null,"blockNumber":null,"transactionIndex":null,"confirmations":0,"from":"0x6c3455607F5592612E9e3754Ba37C63123d68722","gasPrice":{"type":"BigNumber","hex":"0x59682f15"},"maxPriorityFeePerGas":{"type":"BigNumber","hex":"0x59682f00"},"maxFeePerGas":{"type":"BigNumber","hex":"0x59682f15"},"gasLimit":{"type":"BigNumber","hex":"0x07a120"},"to":"0x86C31eA7a0D8996db3cB9da52F3386DA6029a387","value":{"type":"BigNumber","hex":"0x00"},"nonce":27,"data":"0x755edd170000000000000000000000006c3455607f5592612e9e3754ba37c63123d68722","r":"0x8788fa0a000f39aca1543151d690eb089b3a30859ec53a37c41456dbc9debf06","s":"0x6f489e5d8a7393858861daa3a6d31d577dfebc9d37e461e40fb6c04e614b0a47","v":0,"creates":null,"chainId":0}, receipt={"to":"0x86C31eA7a0D8996db3cB9da52F3386DA6029a387","from":"0x6c3455607F5592612E9e3754Ba37C63123d68722","contractAddress":null,"transactionIndex":4,"gasUsed":{"type":"BigNumber","hex":"0x5f4f"},"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","blockHash":"0x00aa21278e8a7cb1d54fa5091b043c089d67a0a8e660986bac0729af428ece3a","transactionHash":"0x64111e3f81675202c90a2aaf5a520c573ed2ff82544d4f76bba3ffc73b2d05a5","logs":[],"blockNumber":10924634,"confirmations":1,"cumulativeGasUsed":{"type":"BigNumber","hex":"0x2cb9d0"},"effectiveGasPrice":{"type":"BigNumber","hex":"0x59682f0e"},"status":0,"type":2,"byzantium":true}, code=CALL_EXCEPTION, version=providers/5.6.8)
at Logger.makeError (index.ts:261:1)
at Logger.throwError (index.ts:273:1)
at Web3Provider.<anonymous> (base-provider.ts:1541:1)
at Generator.next (<anonymous>)
at fulfilled (base-provider.ts:1:1)
Without options
:
Error minting NFT Error: cannot estimate gas; transaction may fail or may require manual gas limit [ See: https://links.ethers.org/v5-errors-UNPREDICTABLE_GAS_LIMIT ] (reason="execution reverted: Transaction value did not equal the mint price", method="estimateGas", transaction={"from":"0x6c3455607F5592612E9e3754Ba37C63123d68722","to":"0x86C31eA7a0D8996db3cB9da52F3386DA6029a387","data":"0x755edd170000000000000000000000006c3455607f5592612e9e3754ba37c63123d68722","accessList":null}, error={"code":-32603,"message":"execution reverted: Transaction value did not equal the mint price","data":{"originalError":{"code":3,"data":"0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002e5472616e73616374696f6e2076616c756520646964206e6f7420657175616c20746865206d696e74207072696365000000000000000000000000000000000000","message":"execution reverted: Transaction value did not equal the mint price"}}}, code=UNPREDICTABLE_GAS_LIMIT, version=providers/5.6.8)
at Logger.makeError (index.ts:261:1)
at Logger.throwError (index.ts:273:1)
at checkError (json-rpc-provider.ts:78:1)
at Web3Provider.<anonymous> (json-rpc-provider.ts:603:1)
at Generator.throw (<anonymous>)
at rejected (json-rpc-provider.ts:1:1)
Any help on how to fix this is appreciated.