[SOLVED] Moralis.Web3API.token.getTokenIdMetadata doesn't return token_uri or metadata for most collections

I am running the code from this tutorial on developing a rarity app:

And for some reason, the following returns null for token_uri and metadata for most collection addresses I put through

  const NFTs = await Moralis.Web3API.token.getAllTokenIds({
    address: collectionAddress,
  });

  const NFTMeta = await Moralis.Web3API.token.getTokenIdMetadata({
    address: collectionAddress, token_id: "1",
  });
  //
  console.log("NFTMeta: ", NFTMeta)

This is the output with one of the addresses I get:

NFTMeta:  {
  token_address: '0x0eff88e66eb717f8f7e0701345f1cc119b487f86',
  token_id: '1',
  block_number_minted: '14152909',
  owner_of: '0x75aca769c4a4479174b0679b1d95aa4d97662a23',
  block_number: '14152909',
  amount: '1',
  contract_type: 'ERC721',
  name: 'Fortune Friends Club',
  symbol: 'FFC',
  token_uri: null,
  metadata: null,
  synced_at: null,
  is_valid: 0,
  syncing: 1,
  frozen: 0
}

Does anyone know why that is the case?

try to resync the uri and metadata :raised_hands: sometimes this could happen

https://docs.moralis.io/misc/faq#why-is-metadata-null-for-some-nfts

In the post they suggested this

make a request to token_uri provided and get the metadata yourself.

How can I do this?

that’s in the case you have the token_uri but your token_uri is also null so you need to first resync the URI then if you want fetch it by yourself as a REST API using fetch or external libraries such as axios.

Otherwise you can also resync the metadata to get the latest metadata

Thanks! That actually fixed it :slight_smile:

2 Likes