Having trouble minting

I was able to mint NFT but after compiling and mirgrating contract mint function now comepletely doesnt work. the error Im running in to is :

main.js:203 Uncaught (in promise) ReferenceError: tokenContract is not defined
at mintNft (main.js:203)
at HTMLButtonElement.createItem (main.js:167)
mintNft @ main.js:203
createItem @ main.js:167
async function (async)
createItem @ main.js:145

and here are the lines of code the console keeps referencing

mintNft = async (metadataUrl) =>
  {
    const receipt = await tokenContract.methods.createItem(metadataUrl).send({from: ethereum.selectedAddress});
    return receipt.events.Transfer.returnValues.tokenId;
  }

What tutorial is this in reference to? I have not done the Rarible series but can offer some general tips.

The error message is the clue here:
ReferenceError: tokenContract is not defined

So the tokenContract variable is not created at the time it’s being called. Some possible causes

  • The new contract address and ABI have not been updated in the front end after redeploying
  • The mintNFT() function is being called before the tokenContract instance has been created. I.e. there are async timing issues.
  • Some other issue is preventing the tokenContract variable from being created properly

Tough to say more without seeing all of your code.

1 Like

thank you so much I had to step away and investigate that clue. As you stated my ABI was not updated.

1 Like