@thru/replay
@thru/replay turns chain RPC backfill plus live streaming into a single ordered feed.
Install
Section titled “Install”npm install @thru/replay @thru/sdkWhen To Use It
Section titled “When To Use It”Choose this package when you need a durable ordered feed for analytics, ETL, or event processing and want to decide where the data lands yourself.
Choose a different package when:
- you need persistence, checkpoints, and Drizzle-backed stream definitions on top of the feed: use
@thru/indexer - you need a full app-facing RPC SDK instead of replay primitives: use
@thru/sdk
Entry Point
Section titled “Entry Point”The package is root-only. Import what you need from @thru/replay; there are no public subpath exports.
Main Exports
Section titled “Main Exports”| Export | Use it for |
|---|---|
ChainClient | Connecting to Thru query and streaming services with one client wrapper. |
createBlockReplay | Ordered block replay with optional filters, consensus floor, and block view settings. |
createTransactionReplay | Ordered transaction replay, including optional event payloads. |
createEventReplay | Ordered event replay with reconnect support. |
createAccountReplay | Replaying one account’s state over time. |
createAccountsByOwnerReplay | Replaying all accounts owned by a program with backfill plus live updates. |
ReplayStream | The async iterator that merges backfill and live data into one ordered stream. |
PageAssembler | Reassembling multi-page account updates into complete account payloads. |
ReplaySink and ConsoleSink | Writing replay output to a sink implementation or the console. |
createConsoleLogger and NOOP_LOGGER | Structured logging for replay runs. |
Common Workflows
Section titled “Common Workflows”- Use
createBlockReplay,createTransactionReplay, orcreateEventReplaywhen you want a typed ordered feed for analytics, ETL, or event processing. - Use
createAccountsByOwnerReplaywhen you need to index all accounts owned by a program and keep them current. - Use
ReplayStreamdirectly when you already have your own backfill fetcher and live subscriber. - Use
PageAssemblerwhen you need to assemble multi-page account updates into complete payloads before processing them.
Account Replay
Section titled “Account Replay”Account replay is split into two shapes:
createAccountReplayfor one account address.createAccountsByOwnerReplayfor owner-scoped indexing with backfill, live updates, and reconnect handling.
The replay package depends on generated protobuf types from @thru/sdk/proto internally.
Data Model
Section titled “Data Model”Replay items are ordered by slot, deduplicated across the backfill/live overlap window, and exposed through an AsyncIterable.
ReplaySinkContext tags each item with the replay phase, backfill or live, so downstream code can treat historical and realtime data differently if needed.
Minimal Example
Section titled “Minimal Example”import { ChainClient, createBlockReplay } from "@thru/replay";
const client = new ChainClient({ baseUrl: process.env.CHAIN_RPC_URL! });const replay = createBlockReplay({ client, startSlot: 1_000_000n });
for await (const block of replay) { console.log(block.header?.slot?.toString());}Related Guides
Section titled “Related Guides”- Indexing Overview for package selection and the full indexing guide structure.
- Build an Indexer for a step-by-step guide using
@thru/indexeron top of replay. @thru/indexerfor persistence and checkpoints built on replay.@thru/sdkfor the full app-facing RPC client.