Function Errors

I appreciate the help so far, I am finally able to access my site locally! When I run the site with the console I get the following errors:


Further, when I try to mint using ā€œCreateā€ button I get this error

This is line 203-212

loadItems = async () => {
    const items = await Moralis.Cloud.run("getItems");
    user = await Moralis.User.current();
    items.forEach(item => {
        if (user){
            if (user.attributes.accounts.includes(item.ownerOf)){
                const userItemListing = document.getElementById(`user-item-${item.tokenObjectId}`);
                if (userItemListing) userItemListing.parentNode.removeChild(userItemListing);
                getAndRenderItemData(item, renderUserItem);
                return;

lines 194-199:

loadUserItems = async () => {

    const ownedItems = await Moralis.Cloud.run("getUserItems");

    ownedItems.forEach(item => {

        const userItemListing = document.getElementById(`user-item-${item.tokenObjectId}`);

        if (userItemListing) return;

        getAndRenderItemData(item, renderUserItem);

line 161:
const nftId = await mintNft(nftFileMetadataFilePath);
and lines 179-182:

mintNft = async (metadataUrl) => {

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

    console.log(receipt);

    return receipt.events.Transfer.returnValues.tokenId;

The line that gives an error when the page first runs is line 204:
const items = await Moralis.Cloud.run("getItems"); I included the whole function that includes this line for context above.
I am trying to follow along with the tutorial, and it is an advantage to have the code written on Github already. I just need help tweaking it so it functions properly. Thank you

for this error youā€™ll have to look on what you added as cloud code on your Moralis Server.
this line calls a cloud function named getItems that you have to add it in your cloud code.

for the second error: return receipt.events.Transfer.returnValues.tokenId;
it looks like this receipt doesnā€™t have that Transfer event, you can look on what you have in that receipt (you already have console.log(receipt);)

In the cloud.js file, it looks like that function for getItems is defined here:

Moralis.Cloud.define("getItems", async (request) => {

     

    const query = new Moralis.Query("ItemsForSale");

    query.notEqualTo("isSold", true);

    query.select("uid","askingPrice","tokenAddress","tokenId", "token.token_uri", "token.symbol","token.owner_of","token.id", "user.avatar","user.username");

 

    const queryResults = await query.find({useMasterKey:true});

    const results = [];

 

    for (let i = 0; i < queryResults.length; ++i) {

 

      if (!queryResults[i].attributes.token || !queryResults[i].attributes.user) continue;

 

      results.push({

        "uid": queryResults[i].attributes.uid,

        "tokenId": queryResults[i].attributes.tokenId,

        "tokenAddress": queryResults[i].attributes.tokenAddress,

        "askingPrice": queryResults[i].attributes.askingPrice,

 

        "symbol": queryResults[i].attributes.token.attributes.symbol,

        "tokenUri": queryResults[i].attributes.token.attributes.token_uri,

        "ownerOf": queryResults[i].attributes.token.attributes.owner_of,

        "tokenObjectId": queryResults[i].attributes.token.id,

       

        "sellerUsername": queryResults[i].attributes.user.attributes.username,

        "sellerAvatar": queryResults[i].attributes.user.attributes.avatar,

      });

    }

It looks like thereā€™s a for loop that checks for unsold items, makes sure the results are not 0, and returns the results. I donā€™t see a problem with this partā€¦

On the part with the function mintNFT, Niclas writes this function at 4:45 of the Part 7 video, I might have lost track but I canā€™t seem to find the part where metadataUrl gets initialized or defined. Unless its not a variable here. Again I am still new to the java commands. What is metadataUrl referencing here?

Metadata url usually is the url that points to additional information about a specific token that is in json format, like a name, an image url, a description.

Ok so in the video, he goes on to explain that the transfer event references the _safeMint function in the MorarableToken.sol, which references this function in the ERC721.sol file:

function _mint(address to, uint256 tokenId) internal virtual {

        require(to != address(0), "ERC721: mint to the zero address");

        require(!_exists(tokenId), "ERC721: token already minted");

        _beforeTokenTransfer(address(0), to, tokenId);

        _balances[to] += 1;

        _owners[tokenId] = to;

        emit Transfer(address(0), to, tokenId);

    }

This is the transfer event

Ok, what do I have to change to fix this?

I donā€™t know what you want to fix.

This function still causes errors when I access the page from Chrome. All the pieces are there but for some reason Chrome cannot read it.
Also, later in the video Niclas adds to this block of code:
image
Which does not appear in the version of main.js that I got from Github. Do I need to add this or was it removed in later revisions?

For me it looks like this code adds info to the database in item table. I donā€™t know exactly what happens in that tutorial to answer you exactly if you need or not this code. Maybe it helps to populate the database with some info.

You may be also able to find help in other forum posts, for example maybe here: Solving common problems [Rarible Clone]