[SOLVED] Mint is not working

I have used react moralis
but mint is not working, error: Transaction has been reverted by the EVM
ABI file:
[

{

    "inputs": [

        {

            "internalType": "string",

            "name": "_name",

            "type": "string"

        },

        {

            "internalType": "string",

            "name": "_symbol",

            "type": "string"

        },

        {

            "internalType": "string",

            "name": "_initBaseURI",

            "type": "string"

        },

        {

            "internalType": "string",

            "name": "_initNotRevealedUri",

            "type": "string"

        }

    ],

    "stateMutability": "nonpayable",

    "type": "constructor"

},

{

    "anonymous": false,

    "inputs": [

        {

            "indexed": true,

            "internalType": "address",

            "name": "owner",

            "type": "address"

        },

        {

            "indexed": true,

            "internalType": "address",

            "name": "approved",

            "type": "address"

        },

        {

            "indexed": true,

            "internalType": "uint256",

            "name": "tokenId",

            "type": "uint256"

        }

    ],

    "name": "Approval",

    "type": "event"

},

{

    "anonymous": false,

    "inputs": [

        {

            "indexed": true,

            "internalType": "address",

            "name": "owner",

            "type": "address"

        },

        {

            "indexed": true,

            "internalType": "address",

            "name": "operator",

            "type": "address"

        },

        {

            "indexed": false,

            "internalType": "bool",

            "name": "approved",

            "type": "bool"

        }

    ],

    "name": "ApprovalForAll",

    "type": "event"

},

{

    "anonymous": false,

    "inputs": [

        {

            "indexed": true,

            "internalType": "address",

            "name": "previousOwner",

            "type": "address"

        },

        {

            "indexed": true,

            "internalType": "address",

            "name": "newOwner",

            "type": "address"

        }

    ],

    "name": "OwnershipTransferred",

    "type": "event"

},

{

    "anonymous": false,

    "inputs": [

        {

            "indexed": true,

            "internalType": "address",

            "name": "from",

            "type": "address"

        },

        {

            "indexed": true,

            "internalType": "address",

            "name": "to",

            "type": "address"

        },

        {

            "indexed": true,

            "internalType": "uint256",

            "name": "tokenId",

            "type": "uint256"

        }

    ],

    "name": "Transfer",

    "type": "event"

},

{

    "inputs": [

        {

            "internalType": "address",

            "name": "to",

            "type": "address"

        },

        {

            "internalType": "uint256",

            "name": "tokenId",

            "type": "uint256"

        }

    ],

    "name": "approve",

    "outputs": [],

    "stateMutability": "nonpayable",

    "type": "function"

},

{

    "inputs": [

        {

            "internalType": "address",

            "name": "owner",

            "type": "address"

        }

    ],

    "name": "balanceOf",

    "outputs": [

        {

            "internalType": "uint256",

            "name": "",

            "type": "uint256"

        }

    ],

    "stateMutability": "view",

    "type": "function"

},

{

    "inputs": [],

    "name": "baseExtension",

    "outputs": [

        {

            "internalType": "string",

            "name": "",

            "type": "string"

        }

    ],

    "stateMutability": "view",

    "type": "function"

},

{

    "inputs": [],

    "name": "cost",

    "outputs": [

        {

            "internalType": "uint256",

            "name": "",

            "type": "uint256"

        }

    ],

    "stateMutability": "view",

    "type": "function"

},

{

    "inputs": [

        {

            "internalType": "uint256",

            "name": "tokenId",

            "type": "uint256"

        }

    ],

    "name": "getApproved",

    "outputs": [

        {

            "internalType": "address",

            "name": "",

            "type": "address"

        }

    ],

    "stateMutability": "view",

    "type": "function"

},

{

    "inputs": [

        {

            "internalType": "address",

            "name": "owner",

            "type": "address"

        },

        {

            "internalType": "address",

            "name": "operator",

            "type": "address"

        }

    ],

    "name": "isApprovedForAll",

    "outputs": [

        {

            "internalType": "bool",

            "name": "",

            "type": "bool"

        }

    ],

    "stateMutability": "view",

    "type": "function"

},

{

    "inputs": [],

    "name": "maxMintAmount",

    "outputs": [

        {

            "internalType": "uint256",

            "name": "",

            "type": "uint256"

        }

    ],

    "stateMutability": "view",

    "type": "function"

},

{

    "inputs": [],

    "name": "maxSupply",

    "outputs": [

        {

            "internalType": "uint256",

            "name": "",

            "type": "uint256"

        }

    ],

    "stateMutability": "view",

    "type": "function"

},

{

    "inputs": [

        {

            "internalType": "uint256",

            "name": "_mintAmount",

            "type": "uint256"

        }

    ],

    "name": "mint",

    "outputs": [],

    "stateMutability": "payable",

    "type": "function"

},

{

    "inputs": [],

    "name": "name",

    "outputs": [

        {

            "internalType": "string",

            "name": "",

            "type": "string"

        }

    ],

    "stateMutability": "view",

    "type": "function"

},

{

    "inputs": [],

    "name": "notRevealedUri",

    "outputs": [

        {

            "internalType": "string",

            "name": "",

            "type": "string"

        }

    ],

    "stateMutability": "view",

    "type": "function"

},

{

    "inputs": [],

    "name": "owner",

    "outputs": [

        {

            "internalType": "address",

            "name": "",

            "type": "address"

        }

    ],

    "stateMutability": "view",

    "type": "function"

},

{

    "inputs": [

        {

            "internalType": "uint256",

            "name": "tokenId",

            "type": "uint256"

        }

    ],

    "name": "ownerOf",

    "outputs": [

        {

            "internalType": "address",

            "name": "",

            "type": "address"

        }

    ],

    "stateMutability": "view",

    "type": "function"

},

{

    "inputs": [

        {

            "internalType": "bool",

            "name": "_state",

            "type": "bool"

        }

    ],

    "name": "pause",

    "outputs": [],

    "stateMutability": "nonpayable",

    "type": "function"

},

{

    "inputs": [],

    "name": "paused",

    "outputs": [

        {

            "internalType": "bool",

            "name": "",

            "type": "bool"

        }

    ],

    "stateMutability": "view",

    "type": "function"

},

{

    "inputs": [],

    "name": "renounceOwnership",

    "outputs": [],

    "stateMutability": "nonpayable",

    "type": "function"

},

{

    "inputs": [],

    "name": "reveal",

    "outputs": [],

    "stateMutability": "nonpayable",

    "type": "function"

},

{

    "inputs": [],

    "name": "revealed",

    "outputs": [

        {

            "internalType": "bool",

            "name": "",

            "type": "bool"

        }

    ],

    "stateMutability": "view",

    "type": "function"

},

{

    "inputs": [

        {

            "internalType": "address",

            "name": "from",

            "type": "address"

        },

        {

            "internalType": "address",

            "name": "to",

            "type": "address"

        },

        {

            "internalType": "uint256",

            "name": "tokenId",

            "type": "uint256"

        }

    ],

    "name": "safeTransferFrom",

    "outputs": [],

    "stateMutability": "nonpayable",

    "type": "function"

},

{

    "inputs": [

        {

            "internalType": "address",

            "name": "from",

            "type": "address"

        },

        {

            "internalType": "address",

            "name": "to",

            "type": "address"

        },

        {

            "internalType": "uint256",

            "name": "tokenId",

            "type": "uint256"

        },

        {

            "internalType": "bytes",

            "name": "_data",

            "type": "bytes"

        }

    ],

    "name": "safeTransferFrom",

    "outputs": [],

    "stateMutability": "nonpayable",

    "type": "function"

},

{

    "inputs": [

        {

            "internalType": "address",

            "name": "operator",

            "type": "address"

        },

        {

            "internalType": "bool",

            "name": "approved",

            "type": "bool"

        }

    ],

    "name": "setApprovalForAll",

    "outputs": [],

    "stateMutability": "nonpayable",

    "type": "function"

},

{

    "inputs": [

        {

            "internalType": "string",

            "name": "_newBaseExtension",

            "type": "string"

        }

    ],

    "name": "setBaseExtension",

    "outputs": [],

    "stateMutability": "nonpayable",

    "type": "function"

},

{

    "inputs": [

        {

            "internalType": "string",

            "name": "_newBaseURI",

            "type": "string"

        }

    ],

    "name": "setBaseURI",

    "outputs": [],

    "stateMutability": "nonpayable",

    "type": "function"

},

{

    "inputs": [

        {

            "internalType": "uint256",

            "name": "_newCost",

            "type": "uint256"

        }

    ],

    "name": "setCost",

    "outputs": [],

    "stateMutability": "nonpayable",

    "type": "function"

},

{

    "inputs": [

        {

            "internalType": "string",

            "name": "_notRevealedURI",

            "type": "string"

        }

    ],

    "name": "setNotRevealedURI",

    "outputs": [],

    "stateMutability": "nonpayable",

    "type": "function"

},

{

    "inputs": [

        {

            "internalType": "uint256",

            "name": "_newmaxMintAmount",

            "type": "uint256"

        }

    ],

    "name": "setmaxMintAmount",

    "outputs": [],

    "stateMutability": "nonpayable",

    "type": "function"

},

{

    "inputs": [

        {

            "internalType": "bytes4",

            "name": "interfaceId",

            "type": "bytes4"

        }

    ],

    "name": "supportsInterface",

    "outputs": [

        {

            "internalType": "bool",

            "name": "",

            "type": "bool"

        }

    ],

    "stateMutability": "view",

    "type": "function"

},

{

    "inputs": [],

    "name": "symbol",

    "outputs": [

        {

            "internalType": "string",

            "name": "",

            "type": "string"

        }

    ],

    "stateMutability": "view",

    "type": "function"

},

{

    "inputs": [

        {

            "internalType": "uint256",

            "name": "index",

            "type": "uint256"

        }

    ],

    "name": "tokenByIndex",

    "outputs": [

        {

            "internalType": "uint256",

            "name": "",

            "type": "uint256"

        }

    ],

    "stateMutability": "view",

    "type": "function"

},

{

    "inputs": [

        {

            "internalType": "address",

            "name": "owner",

            "type": "address"

        },

        {

            "internalType": "uint256",

            "name": "index",

            "type": "uint256"

        }

    ],

    "name": "tokenOfOwnerByIndex",

    "outputs": [

        {

            "internalType": "uint256",

            "name": "",

            "type": "uint256"

        }

    ],

    "stateMutability": "view",

    "type": "function"

},

{

    "inputs": [

        {

            "internalType": "uint256",

            "name": "tokenId",

            "type": "uint256"

        }

    ],

    "name": "tokenURI",

    "outputs": [

        {

            "internalType": "string",

            "name": "",

            "type": "string"

        }

    ],

    "stateMutability": "view",

    "type": "function"

},

{

    "inputs": [],

    "name": "totalSupply",

    "outputs": [

        {

            "internalType": "uint256",

            "name": "",

            "type": "uint256"

        }

    ],

    "stateMutability": "view",

    "type": "function"

},

{

    "inputs": [

        {

            "internalType": "address",

            "name": "from",

            "type": "address"

        },

        {

            "internalType": "address",

            "name": "to",

            "type": "address"

        },

        {

            "internalType": "uint256",

            "name": "tokenId",

            "type": "uint256"

        }

    ],

    "name": "transferFrom",

    "outputs": [],

    "stateMutability": "nonpayable",

    "type": "function"

},

{

    "inputs": [

        {

            "internalType": "address",

            "name": "newOwner",

            "type": "address"

        }

    ],

    "name": "transferOwnership",

    "outputs": [],

    "stateMutability": "nonpayable",

    "type": "function"

},

{

    "inputs": [

        {

            "internalType": "address",

            "name": "_owner",

            "type": "address"

        }

    ],

    "name": "walletOfOwner",

    "outputs": [

        {

            "internalType": "uint256[]",

            "name": "",

            "type": "uint256[]"

        }

    ],

    "stateMutability": "view",

    "type": "function"

},

{

    "inputs": [],

    "name": "withdraw",

    "outputs": [],

    "stateMutability": "payable",

    "type": "function"

}

]

you may need to share more of the code, not only the abi

const {authenticate, isAuthenticated, user, Moralis, isInitialized, isWeb3Enabled, enableWeb3 } = useMoralis();

const contract = new web3.eth.Contract(contractABI, contractAddress);

Mint:
await contract.methods.mint(mintAmount).send({gasLimit: String(totalGasLimit),
from: user.get(‘ethAddress’), to: contractAddress, value: totalCostWei}).once(“error”, (err) => {
})

you get a specific error? what doesn’t work

you can also try to use Moralis.executeFunction or the equivalent from react

now got UNPREDICTABLE_GAS_LIMIT error

Have you tried to use Moralis.executeFuntion as cryptokid said earlier? its a lot easier using moralis

yes same error
Error: cannot estimate gas; transaction may fail or may require manual gas limit

const readOptions = {
contractAddress: contractAddress,
functionName: ‘mint’,
abi: contractABI,
params: {
_mintAmount: 1
}
};
const message = await Moralis.executeFunction(readOptions);
console.log(message);

Note: this code is working with some contract but this contract (abi) is working with non moralis dapp

it might be a check inside the smart contract that youre not passing. does the mint require a msg.value? this might have to do with the transaction may fail

check the contract for any require statements which may be the cause for this

This is the mint function in the contract:

function mint(uint256 _mintAmount) public payable {
uint256 supply = totalSupply();
require(!paused);
require(_mintAmount > 0);
require(_mintAmount <= maxMintAmount);
require(supply + _mintAmount <= maxSupply);
if (msg.sender != owner()) {
require(msg.value >= cost * _mintAmount);
}
for (uint256 i = 1; i <= _mintAmount; i++) {
_safeMint(msg.sender, supply + i);
}
}

well indeed as i said you have to pass a msg.value, you can do it inside the read option like so

const readOptions = {
  contractAddress: contractAddress,
  functionName: ‘mint’,
  abi: contractABI,
  params: {
    _mintAmount: 1
  },
  msgValue: Moralis.Units.ETH("0.5")  // use here your price for 1 token
};
1 Like

also as i can see if you re making this contract call as the contract owner you dont need to pass a msgValue, but make sure that the contract is not paused and other checks are true

It’s working now. Thank you

1 Like