0

On my mint contract abi it says that the internal type is uint256 and the token mint price is 0.01 ETH so i'm not sure how to convert this to uint256 in the frontend?

  {
    "inputs": [
      { "internalType": "uint256", "name": "_mintAmount", "type": "uint256" }
    ],
    "name": "mint",
    "outputs": [],
    "stateMutability": "payable",
    "type": "function"
  },

I'm using ethers.js to interact with the contract, what is the best way to pass the value as unit256?

Here is the error that i get:

MetaMask - RPC Error: execution reverted: Invalid mint amount!

Here is how i'm calling to the frontent

  const mintContract = async () => {
    if (contract) {
      try {
        const tx = contract.mint(utils.parseUnits("0.01"));
        tx.wait();
      } catch (error) {
        await setError(true);
      }
    }
  };

1 Answer 1

0

the problem is that you are not sending 0.01 ether with the transaction. You are telling the contract to mint 0.01 ..

try this and make sure you have ether

  const mintContract = async () => {
    if (contract) {
      try {
        const numberOfTokenToMint = 1;
        const options = {value: utils.parseUnits("0.01")}
        const tx = await contract.mint(numberOfTokenToMint, options);
        await tx.wait();
      } catch (error) {
        await setError(true);
      }
    }
  };
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.