Rarible Clone Part 7 - Mint NFT function issue: recepit.events is empty

I seem to be having issues with the Mint NFT function:

The receipt returned from my createItem method in my token’s solidity file, seems to have an empty events subobject:

Console Log:

mintNFT function code from main.js

  const mintNft = async (metadataUrl) => {
    const receipt = await tokenContract.methods.createItem(metadataUrl).send({from: ethereum.selectedAddress});
    console.log("minted, tokenID: ", receipt);
    console.log('events:: ', JSON.stringify(receipt.events));
    console.log('transfer :: ', JSON.stringify(receipt.events.Transfer));
    // events seems to be empty here:
    return receipt.events.Transfer.returnValues.tokenId;
  }

TestToken.js (What I’m naming this instead of MorarableToken) Solidity code:

pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/utils/Counters.sol";

contract TestToken is ERC721 {
    using Counters for Counters.Counter;
    Counters.Counter private _tokenIds;

    constructor() ERC721("TestToken", "TEST") {}

    struct Item {
        uint256 id;
        address creator;
        string uri;
    }

    mapping(uint256 => Item) public Items;

    function createItem(string memory uri) public returns (uint256) {
        _tokenIds.increment();
        uint256 newItemId = _tokenIds.current();
        _safeMint(msg.sender, newItemId);

        Items[newItemId] = Item(newItemId, msg.sender, uri);

        return newItemId;
    }

    function tokenURI(uint256 tokenId)
        public
        view
        override
        returns (string memory)
    {
        require(
            _exists(tokenId),
            "ERC721Metadata: URI query for nonexistent token"
        );

        return Items[tokenId].uri;
    }
}

Has anyone ran into a similar bug before / any tips to help me begin debugging this?

Hi @spencer_dev,

Could you try checking out this list of common issues devs usually face while recreating the variable clone. It will help you diagnose your issue faster. If you have any further issues, do let me know. :slight_smile:

Happy BUIDLing! :man_mechanic:

Hi Malik. Sadly none of them have worked for me :frowning: Off to do some background reading and perhaps try a different approach than moralis for user minting if problems persist.

For context I’m doing a react + next app so just referencing the tut while I have to write slightly different code.

I’m still using Moralis elsewhere in my project though :slight_smile: I especially find the getNFTs() function to be helpful

Hey @spencer_dev

Please make sure you have provided correct api (https://github.com/MoralisWeb3/youtube-tutorials/blob/main/rarible-clone/frontend/abi.js)

I’ve just tested it again and it works correctly

I just tried again and it seems to be working now! I also re-did the previous tutorial steps and including a re-run of the migrations and set up a new ganache instance. Awesome :smiley: Now I have this working in my nextJS / React app. Thank you for the response & for validating the api works !

3 Likes