Pagination

Cursor, before and page-number paging.

# Pagination

Three endpoints return lists that can be paged. Each uses the style that fits its data.

| Endpoint | Style | Request | Reply |
| --- | --- | --- | --- |
| [Latest blocks](https://docs.rarebl.com/api/block/latest) | Height cursor | `before`, `limit` (1 to 25, default 10) | `items`, `next` |
| [Block](https://docs.rarebl.com/api/block/get) | Page number | `page` (default 1), `limit` (1 to 100, default 25) | `txs`, `page`, `pages`, `total` |
| [Address transactions](https://docs.rarebl.com/api/address/transactions) | Opaque cursor | `cursor`, `limit` (1 to 100, default 25) | `items`, `next` |
| [Mempool](https://docs.rarebl.com/api/tx/mempool) | None | `limit` (1 to 100, default 25) | `items` |

## Cursor on `before` (blocks)

`next` is the **lowest height** of the page. Pass it back as `before` to get the blocks below it. `next` is `null` at block 0 (on TRON, at the first block the node holds).

~~~bash
curl "https://api.rarebl.com/open/block/latest?chain=btc&limit=10"
curl "https://api.rarebl.com/open/block/latest?chain=btc&limit=10&before=975843"
~~~

## Page number (block transactions)

[Block](https://docs.rarebl.com/api/block/get) pages the block's transactions. Use `page` from 1 up to `pages`. `total` is the number of transactions in the block.

~~~bash
curl "https://api.rarebl.com/open/block/get?chain=btc&id=975851&page=2&limit=100"
~~~

## Opaque cursor (address transactions)

Pass `next` back as `cursor`, unchanged. Do not build or edit a cursor yourself. `next` is `null` on the last page.

~~~bash
curl "https://api.rarebl.com/open/address/transactions?chain=dash&address=XgNx6VFjYhSKPxXcjcPvad61DPSQhdiJDT&limit=25"
~~~

Address history is available on DASH only today: see [Coverage and limits](https://docs.rarebl.com/limits-today).

## A paging loop

~~~js
let before;
const blocks = [];
for (let page = 0; page < 5; page++) {
  const url = new URL('https://api.rarebl.com/open/block/latest');
  url.search = new URLSearchParams({ chain: 'btc', limit: '50', ...(before && { before }) });
  const { data } = await (await fetch(url)).json();
  blocks.push(...data.items);
  if (data.next === null) break;
  before = String(data.next);
}
~~~

Back to the Rarebl AI documentation index