I am trying to build a very simple web3 application. The goal is to be able to mint a NFT on button click and perform a transaction for a specific amount of ETH with metamask. For that I want to use moralis (but I am also open for alternatives). Also I am using Rinkeby testnetwork for this.
This whole topic is pretty new for me and I am trying to figure out how I can do that but I keep getting error after error.
Login / Logout is already working and I build a simple UI. After connecting to MetaMask I want the user to select the amount he wants to mint from the contract and then click "Mint now". This transaction however keeps failing.
The error is:
- MetaMask - RPC Error: execution reverted {code: -32000, message: 'execution reverted'}
- moralis.js:42068 Uncaught (in promise) Error: cannot estimate gas; transaction may fail or may require manual gas limit (error={"code":-32000,"message":"execution reverted"}, method="estimateGas", transaction={"from":"X","to":"Y","data":"Z","accessList":null}, code=UNPREDICTABLE_GAS_LIMIT, version=providers/5.5.2) at Logger.makeError (moralis.js:42068:21) at Logger.throwError (moralis.js:42077:20) at checkError (moralis.js:47333:16) at Web3Provider. (moralis.js:47866:47) at step (moralis.js:47255:23) at Object.throw (moralis.js:47236:53) at rejected (moralis.js:47228:65)
My code is:
async function moralisWeb3() {
// Get the EthersJs library
const ethers = Moralis.web3Library;
// Get a (ethers.js) web3Provider
const web3Provider = await Moralis.enableWeb3();
// Enable web3 and get the initialized web3 instance from Web3.js
await Moralis.enableWeb3();
const web3Js = new Web3(Moralis.provider);
// connector
const web3 = await Moralis.enableWeb3();
const options = {
contractAddress: contractID,
functionName: "mint",
abi: ABI,
params: {
_mintAmount: "2"
}
};
const transaction = await Moralis.executeFunction(options);
const receipt = await transaction.wait();
console.log(receipt);
document.getElementById("btn-mint").onclick = moralisWeb3;
}
Can someone help me to build this?