Going to next page of the result .next() not working

Hello,
I am reading the NFTs using web3api in a react project. I get the correct result back. But the problem is that when I use .next() to get the next 100 results, it just skips the last page.
for example, if I have 130 in total and the limit is 100, it doesn’t go through the loop to get the next page.

this is my code:

const options = {
        address: '0x2cdfc342877b19e9385f72408de34d2c5fd06dfc',
        chain: 'mumbai',
        token_address: '0xa5ce390be1d19cc41ecb26c3174e99ead3a3e45a',
        limit: 100,
      };

      let result = await Web3Api.account.getNFTsForContract(options);

      const total = result.total;

      let totalNFTs = result.result ?? [];

      while ((result as any).next) {
        result = await (result as any).next();
        result.result && (totalNFTs = [...totalNFTs, ...result.result]);
      }
console.log('total in response',total)
console.log('total after calling next',totalNFTs.length)

I don’t know what I did wrong here

it could depend on what version of the sdk you are using, there was a bug in the past when it was starting from 0 instead of 1 and it was skipping last page

So I updated moralis and react-moralis to the latest version. But apperantly they don’t work well together. right?
npm i moralis@latest react-moralis@latest

yes, you have to use specific versions, not any combination works well

The latest versions you can use are [email protected] and [email protected].

1 Like