Can't access object metadata

Hey guys I have a for loop going here everything logs to console for each NFT before the data was showing with metadata.data.name but now in the for loop for some reason I don’t know how to grab the data from the object. If anyone could help would mean a lot thank you! :slight_smile:

await nfts.forEach(function(nft){

                console.log(nft)

                let url = nft.token_uri;

                const params = { theUrl : url }

                const metadata = Moralis.Cloud.run("fetchJSON", params);

                console.log(metadata);

               

                document.getElementById("nftboyname").innerHTML = metadata.data.name;

   

                document.getElementById("nftboyinfo").innerHTML = metadata.data.description;

metadata is coming back as a object promise

Try adding await in front of your Moralis.Cloud.run and then add async in front of function(nft).

Make your function async and fix this const metadata = await Moralis.Cloud.run("fetchJSON", params);

I have await in front of const nfts = await Moralis.Web3.getNFTs(); when I add it in front of Moralis.Cloud.run(“fetchJSON”, params); the function does not run

async function nftgallery(){

            const nfts = await Moralis.Web3.getNFTs();

            nfts.forEach(function(nft){

            console.log(nft)

            nft = nft

            let url = nft.token_uri;

            const params = { theUrl : url }

            const metadata = Moralis.Cloud.run("fetchJSON", params);

            console.log(metadata)

           

            document.getElementById("nftboyname").innerHTML += meta.data.name;

            //document.getElementById("nftboyinfo").innerHTML = metadata.data.description;



            //var pfi2 = metadata.data.image

            //document.getElementById("nftboyimage").src = pfi2;

           

                        })}

I have 2 awaits in my function and it won’t run when I remove it from await Moralis.Web3.getNFTs(); and add it to Moralis.Cloud.run(“fetchJSON”, params); it does not run but when i remove the first and add it to the cloud run I get back meta is not defined

Did you add async to nfts.forEach(function(nft){ as well? If so, what error do you get?

Yes when I do that and add await to Moralis.cloud I get Uncaught ReferenceError: nftgallery is not defined for the button im pressing to call the script

How are you calling nftgallery from your button?

NFT GALLERY

like this

<button onclick=“nftgallery()”>NFT GALLERY</button>

sorry the original only posted text like this without the *

I figured out the problem async needed to go here

nfts.forEach(async function(nft){

thanks guys