DAS API Pagination
Explores the different pagination mechanisms offered by the DAS API.
Introduction
The DAS API methods will only return up to 1000 records. If you need to retrieve more than 1000 items, you will need to paginate the records. This is achieved by making multiple API calls and crawling through multiple “pages” of data. We support two mechanisms: page-based and keyset pagination.
We recommend page-based pagination for beginners. It is the simplest and best way to get started. Keyset pagination is recommended for advanced users who need to query across large (500k+) datasets efficiently.
Sorting Options
With the DAS API, you can sort the data by different fields:
id
: Sort by the asset ID in binary (default).created
: Sort by the date the asset was created.recent_action
: Sort by the date the asset was last updated (not recommended).none
: Do not sort the data (not recommended).
Disabling the sorting will yield the fastest results, but since the data is not ordered, you may have inconsistent results when paginating.
Pagination Options
Page-based
With this method, the user specifies the page number and the number of items they want per page. To iterate to the next page, increment the page number. This is easy, intuitive, and fast for most use cases.
Using pages requires the database to crawl across all items until it reaches the next page. For example, if you ask for page 100 and page size 1000, the database must traverse the first 1M records before returning your data.
For this reason, page-based pagination is not recommended for large datasets. Keyset pagination is far better suited for these types of workloads.
Keyset
With this method, the user defines pages by providing conditions that filter the data set. For example, you can say, “Get me all assets with an ID > X but an ID < Y”. The user can traverse the entire dataset by modifying X or Y on each call. We provide two methods of keyset pagination:
- Cursor-based – Easier to use but less flexible.
- Range-based – More complex but very flexible.
Keyset pagination is only supported when sorting by id
.
Cursor-based
A DAS query without any pagination parameters will return a cursor. You can give the cursor to the DAS API to continue from where you left off.
At the time of writing, the cursor will be the last asset ID of the response; however, the cursor design is flexible and can support any string.
Range-based
To query across a range, you can specify before
and/or after
. The query is essentially identical to “get me all assets after X but before Y”. You can traverse the dataset by updating each call’s before or after parameter.
Parallel Querying with Keysets (advanced)
Advanced users needing to query large datasets (e.g., entire compressed NFT collections) must use keyset-based pagination for performance reasons. The following example shows how users can parallel query by partitioning the Solana address range and leveraging the before/after parameters. This method is fast, efficient, and safe. If you have any questions or need help, don’t hesitate to reach out on Discord!