metaplex-foundation / metaplex

A directory of what the Metaplex Foundation works on!

Home Page:https://metaplex.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can not get mint address from NFT metadata

JopaCat opened this issue · comments

Using TS and there is the code:

let nftMetadata: any[] = [];
let allMetadata: any[] = [];
const owner = new PublicKey(publicKey);
const allNfts = await metaplex.nfts().findAllByOwner({
    owner: owner
});
allNfts.map((nft) => (
    allMetadata.push({
        'mintAddress': (nft.mintAddress),
        'uri': nft.uri 
    })
));

for (var i = 0; i < allMetadata.length; i++) {
    await getNftMetadata(allMetadata[i], publicKey)
    .then((data) => {
        nftMetadata.push(data);
    })
    .catch((err) => {
        logError(err);
    })
}
return nftMetadata;

Line 'mintAddress': (nft.mintAddress) returning Property 'mintAddress' does not exist on type 'Metadata<JsonMetadata<string>> | Nft | Sft'. Property 'mintAddress' does not exist on type 'Nft'.
So there is the metadata i receiving:

{
  model: 'metadata',
  address: Pda {
    _bn: <BN: 349b58137ce509a996500f297dcf43fd8050dec2ef4bafb242d87bb3385d8a0d>,
    bump: 253
  },
  mintAddress: PublicKey {
    _bn: <BN: 73400b567ac34be4f2a79e4889dd830e8bf18c79b993776006fe91bdcea33533>
  },
  updateAuthorityAddress: PublicKey {
    _bn: <BN: 5b563cbd973fca8abbbea3017768faaf8504641955cc67ea2e57e62439ed6d2d>
  },
  json: null,
  jsonLoaded: false,
  name: '',
  symbol: 'tSHP',
  uri: 'https://nftstorage.link/ipfs/bafybeicsimixbjpuc7p6w3ttngjtzlxm4m3rxjyanvyfutrk6ou6c6k7xi/823.json',
  isMutable: true,
  primarySaleHappened: true,
  sellerFeeBasisPoints: 600,
  editionNonce: 254,
  creators: [
    { address: [PublicKey], verified: true, share: 0 },
    { address: [PublicKey], verified: false, share: 100 }
  ],
  tokenStandard: 0,
  collection: null,
  collectionDetails: null,
  uses: null
}

I got the same thing with typescript not recognizing the mintAddress in the type definition.

I got the same thing with typescript not recognizing the mintAddress in the type definition.

Sorry forgot to update here:

select each item response like this:

allNfts.forEach(item => (

if (item.model = "nft") {
item as Nft

}

if (item.model = "sft") {}
item as Sft

))