Skip to main content

Overview

Paginator<T> is an async-iterable class returned by all collection methods on the Agent class (transactions, executions, logs, rewards). It provides three ways to consume paginated API results:
  1. Async iteration with for await...of — automatically pages through all results.
  2. .first(count) — fetch the first N items as an array.
  3. .page(num, opts) — fetch a specific page with metadata.
You never construct a Paginator directly. It is returned by agent methods like agent.transactions(), agent.executions(), agent.rewards(), and others.

Usage Patterns

Pattern 1: Async Iteration

The paginator implements AsyncIterable<T>, so you can use for await...of to iterate over all items across all pages. The paginator automatically fetches subsequent pages as needed.
Async iteration fetches all pages sequentially. For large datasets, consider using .first() or .page() to limit the amount of data retrieved.

Pattern 2: First N Items

Use .first(count) to get an array of the first N items. This fetches only the pages needed to fulfill the request.
When called without an argument, .first() returns the first page of items using the configured page size.

Pattern 3: Specific Page

Use .page(num, opts) to fetch a specific page and get pagination metadata alongside the items.

Class Reference

Paginator<T>

Symbol.asyncIterator

Enables for await...of iteration. Automatically fetches pages until all items have been yielded. Returns: AsyncIterableIterator<T>

page()

Fetch a specific page of results with pagination metadata.
number
required
The 1-based page number to fetch.
{ limit?: number }
Optional override for the page size.
number
Number of items per page. Defaults to the limit configured when the paginator was created (typically 20).
Returns: Promise<PaginatedResponse<T>>

first()

Fetch the first N items as an array.
number
Number of items to return. When omitted, returns the first page using the configured page size.
Returns: Promise<T[]>

PaginatedResponse<T>

The response object returned by .page().

PageFetcher<T>

The internal type for the function that fetches a page of results. This is used internally by the SDK and is not needed for normal usage.

Methods That Return Paginators

The following Agent methods return Paginator instances: All accept an optional PaginationOptions parameter:

Building a Paginated UI

This example shows how to use .page() to build a paginated list with navigation.