Sync NFT metadata when using getNFTs()

I’m using getNFTs() to query NFTs from a collection:

const Web3Api = useMoralisWeb3Api();

  const options = {
    chain: 'matic',
    address: '0x67f4732266c7300cca593c814d46bee72e40659f',
  };

  const fetchAllNFTs = async (options) => {
    const polygonNFTs = await Web3Api.account.getNFTs(options);
    const polyResults = polygonNFTs.result;

    console.log('NFTs', polyResults);
  };

In the results, I’m seeing metadata for only some NFTs in the collection when they all have metadata on chain.

Does Moralis have any option to force metadata sync for all NFTs in a collection or the ones that are queried?

the nfts that are queried are added to a queue only if the token uri points to IPFS

if not, you can use resyncMetadata endpoint to force a resync, you will have to make a request per token id, you can do that directly in web3api interface in admin interface too

Oh, it looks like this collection includes a couple different types of ERC721.

Is there a built-in option in the getNFTs or getNFTsForContract() to filter the results from the function?

The results object includes “name” where I only want items with “name” === “ZED Horse”, not “ZEDNAME” or “ZED Racehorse Skins”

I could filter the results but I want the full 100 results pre-filtered if possible.

there isn’t a way to filter that here, you can try to filter with searchNFts, but that may not help you

same token address has different names?

This item on OS shows it’s contract address is this which has multiple ERC721 tokens: https://polygonscan.com/address/0x67f4732266c7300cca593c814d46bee72e40659f#tokentxnsErc721

If I run these functions below…
This one includes NFTs with name: “ZED Horse”

// Get NFTs of owner from contract
  const Web3Api = useMoralisWeb3Api();

  const options = {
    chain: 'polygon',
    address: '0x5Ffccbf0eAf209C228092E10302B6dA953d7beA8',
    token_address: '0x67F4732266C7300cca593C814d46bee72e40659F',
  };

  const fetchAllNFTs = async (options) => {

    const polygonNFTs = await Web3Api.account.getNFTsForContract(options);
    const polyResults = polygonNFTs.result;

    console.log('ZED NFTs', polyResults);
  };

Below is the same contract but all tokens includes NFTs with name: “ZED Horse”, name: “ZED Racehorse Nameplate”, and name: “ZED Racehorse Skins”

It looks like there are Horses, Nameplates, and Skins all on the same contract.

  // Get NFTs from contract
  const Web3Api = useMoralisWeb3Api();

  const options = {
    chain: 'polygon',
    address: '0x67F4732266C7300cca593C814d46bee72e40659F',
  };

  const fetchAllNFTs = async (options) => {
    const polygonNFTs = await Web3Api.account.getNFTs(options);
    const polyResults = polygonNFTs.result;

    console.log('ZED NFTs', polyResults);
  }; 

When I try a GET request on the Web3 APIs page here: https://admin.moralis.io/web3apis

/nft/{address}

address=“0x67F4732266C7300cca593C814d46bee72e40659F”

This looks like it returns the proper results for horses only.

You mean that some results are missing?

Can you give an example of a missing result?

I think I see whats wrong, getNFTs address option is for user address only not contract?

https://docs.moralis.io/moralis-dapp/web3-api/nft-api#getnfts

Any way to search NFTs within one collection contract address only?

getNFTsForContact() only gives results if owner address is added yet thats an optional option field:

const options = {
    chain: 'polygon',
    // address: '0x5Ffccbf0eAf209C228092E10302B6dA953d7beA8',
    token_address: '0x67F4732266C7300cca593C814d46bee72e40659F',
  };

  const fetchAllNFTs = async (options) => {
    const resp = await Web3Api.account.getNFTsForContract(options);

    try {
      const data = await resp;
      console.log(data);
    } catch (err) {
      console.error(err);
    }
  };

getNFTs can work for contract addresses but it pulls NFTs that the address has ownership of, just like a wallet address. The contract has minted a lot of its own collection NFTs to itself and also has those other collection NFTs like Nameplate.

If you want to get the NFTs from a single collection itself, then you can use an endpoint like getAllTokenIds or /nft/{address} as you have done.

1 Like

Thanks, that makes sense.

getAllTokenIds() does work way better. Thanks