Rarible Clone Part 7

Error when trying to mint tokens

main.js:140 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading ‘createItem’)
at mintNft (main.js:140:52)
at HTMLButtonElement.createItem (main.js:120:31)

Not sure where the problem is coming from would anyone be able to help out?

My main.js createItem and mintToken function code:

createItem = async () => {

if (createItemFile.files.length == 0){

    alert('please select file')


}else if (createItemNameField.value.length == 0){

    alert('Please give the item a name')



const productFile = new Moralis.File('productFile.jpg', createItemFile.files[0]);

await productFile.saveIPFS();

const productFilePath = productFile.ipfs();

const productFileHash = productFile.hash();

const metadata = {

    name: createItemNameField.value,

    description: createItemDescriptionField.value,

    productFilePath: productFilePath,

    productFileHash: productFileHash,


const productFileMetadataFile = new Moralis.File("metadata.json", {

    base64: btoa(JSON.stringify(metadata)),


  await productFileMetadataFile.saveIPFS();

  const productFileMetadataFilePath = productFileMetadataFile.ipfs();

  const productFileMetadataFileHash = productFileMetadataFile.hash();

  const productId = await mintNft(productFileMetadataFilePath)


  const Item = Moralis.Object.extend("Item");

// Create a new instance of that class.

const item = new Item();

item.set('name', createItemNameField.value)

item.set('description', createItemDescriptionField.value);

item.set('productFilePath', productFilePath);

item.set('productFileHash', productFileHash);

item.set('MetadataFilePath', productFileMetadataFilePath);

item.set('MetadataFileHash', productFileMetadataFileHash);

item.set('nftId', productId);

item.set('nftContractAddress', TOKEN_CONTRACT_ADDRESS);

await item.save();



mintNft = async (metadataUrl) => {

const receipt = await tokenContractAbi.methods.createItem(metadataUrl).send({from: ethereum.selectedAddress});


return receipt.events.Transfer.returnValues.tokenId;


If i remember correctly that tutorial uses web3 for contract interaction, Moralis switched to ethers.js in this time, so either use ethers.js for contract interaction or check this

Check how you’re running mintNft. I think this is the completed example, you can compare your code.