[SOLVED] Is "Get NFTs by contract" working properly?

Hi
I hope all is well.

I just want to double-check if “Get NFTs by contract” is working. The “Try It” is working on the reference page but it returns an empty array when used locally. When I simply replaced getContractNFTs with getNFTOwners it worked fine (I am pulling the metadata from the tokens). So I deduce it is not the parameters (totalRanges and range is just kept as default the only difference between the two in the docs)?

Thanks in advance.

Can you give an example that doesn’t work as expected?

Did you try directly in docs interface?

Yes, docs works fine. Nodejs code window still does not update in real time. I am using it in getServerSideProps in nextjs.

Does not work, returns empty array “[ ]” (not my contract, just for illustration purposes):

const chain = EvmChain.MUMBAI;
    
    const address = '0xeB5E4649CF034dA79C30ce2385B0Dbe7D76623AE';
    
    const totalRanges = 1000;
    
    const range = 1;
    
    await Moralis.start({
        apiKey: process.env.NEXT_PUBLIC_API_KEY,
    });
    
    const response = await Moralis.EvmApi.nft.getContractNFTs({
        address,
        chain,
        totalRanges,
        range,
    });
    console.log(response.result);

Works fine returns 3 tokens:

const chain = EvmChain.MUMBAI;
    
    const address = '0xeB5E4649CF034dA79C30ce2385B0Dbe7D76623AE';
    
    const totalRanges = 1000;
    
    const range = 1;
    
    await Moralis.start({
        apiKey: process.env.NEXT_PUBLIC_API_KEY,
    });
    
    const response = await Moralis.EvmApi.nft.getNFTOwners({
        address,
        chain,
        totalRanges,
        range,
    });
    console.log(response.result);

So the only variable from the docs is that I am using nextjs?

Only other difference is getContractNFTs vs getNFTOwners

try without totalRanges and range parameters here, this contract has only 3 nfts, no need to use ranges

IT works thank you. The contract I was working with also had less than 100 NFT’s

I see this in the docs:

  • Results are limited to 100 per page by default

So those parameters work at > 100?

No, that is something else that you can use when there are more than 10k results or more than 100k results.

For more than 100 results you will use cursor parameter to paginate over the results

1 Like