[SOLVED] getNFTs with users with more than 500 NFTs

Iโ€™m currently using Moralis.Web3API.account.getNFTs() to retrieve all NFTs owned by an address, with a plan to make the result array queriable by NFT name. However, there is a constraint on how many NFTs get returned โ€“ namely, the maximum array length that Moralis returns is 500 long.

This would mean that my query would only be able to search those 500 randomly chosen NFTs, but โ€“ in the case when a user has 1000+ NFTs โ€“ will miss out on the majority of NFTs owned by the user.

What is the correct way of addressing this limitation?

yes, you can use pagination to get the rest of the nfts, and to use order=token_id.DESC for example so that the list of NFTs is not random any more.

1 Like

Continuing the discussion from getNFTs with users with more than 500 NFTs:

Thanks for your response!

Iโ€™ve tried changing my options to include order: "desc". The full line looks like this:

const nfts = await Moralis.Web3API.account.getNFTs({ chain: "eth", address: ..., order: "desc"})

Which looks like it should work, as even my intellisense suggests inserting order into the options. Yet, when I actually run it, I get an error:

{code: 141, error: '[object Object]'}

I wrote "desc" specifically because thatโ€™s whatโ€™s used here: https://docs.moralis.io/moralis-server/web3-sdk/account#gettransactions. Perhaps thatโ€™s the culprit?

I think that different web3api functions have different values for that order parameter. You can test in https://admin.moralis.io/web3Api โ€‹/{address}โ€‹/nft endpoint for now for a more detailed error message for a particular web3api query.

1 Like

How would I do that? All documentation Iโ€™ve read only shows how to call specific functions. Iโ€™ve never been able to find how to access a web3API endpoint.

you access https://admin.moralis.io/web3Api, you click on an api endpoint, then on try now, then add some parameters and then click on execute.

1 Like

Awesome! Problem solved.