I am still making lots of tries and errors. When something goes right, other things go wrong…
I cannot figure out why this error occurs:
This is the current code:
const txt = await mintToken(metadataURI).then(notify)
})();
async function mintToken(_uri){
const encodedFunction = web3.eth.abi.encodeFunctionCall({
name: "mint",
type: "function",
inputs: [{type: 'string', name: 'tokenURI'},]
}, [_uri]);
const options = {
contractAddress: nft_contract_address,
functionName: "mint",
abi: ABI,
params: {
type: 'string',
name: 'tokenURI',
msgValue: Moralis.Units.ETH("0.01")
},
};
const transaction = await Moralis.executeFunction(options);
const result = await transaction.wait();
const transactionParameters = {
to: nft_contract_address,
from: ethereum.selectedAddress,
data: encodedFunction,
};
const txt = await ethereum.request({
method: 'eth_sendTransaction',
params: [transactionParameters]
});
return txt
}
async function notify(_txt){
document.getElementById("resultSpace").innerHTML =
`<input disabled = "true" id="result" type="text" class="form-control" placeholder="Description" aria-label="URL" aria-describedby="basic-addon1" value="Your NFT was minted in transaction ${_txt}">`;
}
This is the contract function:
function mint(string memory tokenURI) external payable {
require(isMintEnabled, 'minting not enabled');
require(mintedWallets[msg.sender] < 5, 'exceeds max per wallet');
require(msg.value == mintPrice, 'wrong value');
require(maxSupply > totalSupply, 'sold out');
mintedWallets[msg.sender]++;
totalSupply++;
uint256 tokenId = totalSupply;
_safeMint(msg.sender, tokenId);
_setTokenURI(tokenId, tokenURI);
}
Could I have any advises, please.