Getalltokenids with cursor not returning all token ids but with next() return all token ids

Hi, Please Help i don’t know why when i used method cursor it returns just 900 token ids from 4200 NFTs but when i used method next() it returns all token ids 4200
i used for cursor this method in link below
https://moralis.zendesk.com/hc/en-us/articles/5294669394578-How-to-use-cursor
and for method next this method below
https://docs.moralis.io/moralis-dapp/web3-api#web3-api-pagination-examples-with-.next

in this is the contract address for the project 0x02f74badce458387ecaef9b1f229afb5678e9aad

but for other contract address the two methods get all token ids

what is the code that you used? small changes may be required to make it work

1 Like

Okay Thanks

This is for curosr

async function get_metadata() {
    try {
        const timer = ms => new Promise(res => setTimeout(res, ms));
		
        let allNFTs = [], cursor = null;

        do {
            //get the first 100 NFT
            const  response = await Moralis.Web3API.token.getAllTokenIds({
                address: "0x02f74badce458387ecaef9b1f229afb5678e9aad",
                chain: "eth",
                limit: 100,
                cursor: cursor,
            });
            allNFTs.push(...response.result);
            await timer(10000);
            cursor = response.cursor;
            console.log(response.result)
            console.log(allNFTs.length)
            console.log(cursor)
        } while (cursor !== "" && cursor != null);
    } finally {
        // Ensures that the client will close when you finish/error
        await client.close();
    }
}

This is for next

async function get_metadata() {
    try {
        const timer = ms => new Promise(res => setTimeout(res, ms));

        //get metadata from the first page
        let NFTs = await Moralis.Web3API.token.getAllTokenIds({
            address: "0x02f74badce458387ecaef9b1f229afb5678e9aad",
            chain: "eth",
            limit: 100,
        });

        let allNFTs = NFTs.result || [];
        console.log(allNFTs)
        console.log(allNFTs.length)

        while (NFTs.next) {
            await timer(10000);
            NFTs = await NFTs.next()
            allNFTs.push(...NFTs.result);
            console.log(allNFTs.length)
        }
    } finally {
        // Ensures that the client will close when you finish/error
        await client.close();
    }
}

seems fine at first look, did you try it few times, same result?

1 Like

yes i try for 3 times but the same result ,but when i try with another contract address the two method gives all token ids

I tried this and got me 4200:

async function get_metadata() {
    
        const timer = ms => new Promise(res => setTimeout(res, ms));
		
        let allNFTs = [], cursor = null;

        do {
            //get the first 100 NFT
            const  response = await Moralis.Web3API.token.getAllTokenIds({
                address: "0x02f74badce458387ecaef9b1f229afb5678e9aad",
                chain: "eth",
                limit: 100,
                cursor: cursor,
            });
            allNFTs.push(...response.result);
            await timer(1000);
            cursor = response.cursor;
            console.log(response.result.length)
            console.log(allNFTs.length)
            console.log(cursor)
        } while (cursor !== "" && cursor != null);
    
}
1 Like

I will try it again , because when i tried the first time got 800 and the second time got 900 and the third time got 900 i don’t know why

it’s works now ,Thank you so much for your help

1 Like