metaplex-foundation / js

A JavaScript SDK for interacting with Metaplex's programs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'mintAddress')

coolb0y opened this issue · comments

I was fetching the nfts owned by a user. (Note:- My task was to load image url as well so I can render it on webpage which I put in metadata uploaded to arweave. If I was able to get image url directly without loading json or there is way to store the image url in nft itself and not in the metadata That would solve my issue as well. )

const myallNft = async () => {
      const myNfts = await metaplex.nfts().findAllByOwner({
          owner: metaplex.identity().publicKey
      });
     console.log('myNfts', myNfts)

Though the data in myNfts is metadata model type see the image below

Screenshot from 2023-03-25 01-16-50

So I added the load method

 myNfts.map(async(nftdata)=>{
       // console.log(nftdata,'nftdata');
        let tempnft = await metaplex.nfts().load({nftdata});
        console.log(tempnft)
      })

But instead of tempnft having metadata loaded. I am getting an error

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'mintAddress')
    at Object.handle (loadMetadata.ts:105:1)
    at OperationClient.ts:70:1
    at Disposable.run (Disposable.ts:33:1)
    at OperationClient.execute (OperationClient.ts:70:1)
    at NftClient.load (NftClient.ts:200:1)
    at Mynfts.jsx:34:1
    at Array.map (<anonymous>)
    at myallNft (Mynfts.jsx:32:1)

The issue was really basic. I once wrote this but vscode shows error so I removed this. But changing lines from

 myNfts.map(async(nftdata)=>{
       // console.log(nftdata,'nftdata');
        let tempnft = await metaplex.nfts().load({nftdata});
        console.log(tempnft)
      })

to this solved my problem


myNfts.map(async (nftdata) => {
        console.log(nftdata.mintAddress.toBase58(), 'nftdata');
        let tempnft = await metaplex.nfts().load({metadata: nftdata});
       
      })