How to use pagination to retrieve all tokens of a given NFT collection

terra.wasm.contractQuery(contractAddr1, 
  {
      "all_tokens":{
        "limit": 30,
        "start_after": 1000 // this is not working
      },
  }
  ).then(res => {
})

I am struggling to use pagination to get all NFT details in a collection. Is there any resource on how to user start_after I can refer to ? . What do you think I am doing wrong here ?

1 Like

Hey kasunOMG!

A few things, first off the answer depends on the collection you are trying to paginate. A few of the early collections on Terra unfortunately have a bug that prevents pagination using all_tokens. More details on the bug here:

Ultimately start_after is expecting a token_id not an offset. So if the contract is not affected by this bug you can use the token_id of the last token in the first query you make.

If you could share the collection Iā€™m happy to come up with an example!

1 Like

Hey Kasun! Try setting start_after to a string, not a number, where the string is the key (id) of the last token on page 1.

1 Like