Skip to main content
@thru/replay turns chain RPC backfill plus live streaming into a single ordered feed.

Install

npm install @thru/replay

When to use it

Choose this package when you only need a durable ordered feed for analytics, ETL, or event processing. Use @thru/indexer when you also want to store the data, checkpoint progress, or mount read routes. Choose a different package when:
  • You need persistence, checkpoints, and read APIs on top of the feed: use @thru/indexer
  • You need a full app-facing RPC SDK instead of replay primitives: use @thru/thru-sdk

Entry point

The package is root-only. Import what you need from @thru/replay; there are no subpath exports.

Main exports

ExportUse it for
ChainClientConnecting to the Thru query and streaming services with one client wrapper.
createBlockReplayOrdered block replay with optional filters, consensus floor, and block view settings.
createTransactionReplayOrdered transaction replay, including optional event payloads.
createEventReplayOrdered event replay with reconnect support.
createAccountReplayReplaying one account’s state over time.
createAccountsByOwnerReplayReplaying all accounts owned by a program with backfill plus live updates.
ReplayStreamThe async iterator that merges backfill and live data into one ordered stream.
PageAssemblerReassembling multi-page account updates into complete account payloads.
ReplaySink and ConsoleSinkWriting replay output to a sink implementation or the console.
createConsoleLogger and NOOP_LOGGERStructured logging for replay runs.
DEFAULT_RETRY_CONFIG, calculateBackoff, withTimeout, delay, TimeoutErrorRetry and timeout helpers for live reconnect behavior.

Common workflows

  • Use createBlockReplay, createTransactionReplay, or createEventReplay when you want a typed ordered feed for analytics, ETL, or event processing.
  • Use createAccountsByOwnerReplay when you need to index all accounts owned by a program and keep them current.
  • Use ReplayStream directly when you already have your own backfill fetcher and live subscriber.
  • Use PageAssembler when you need to assemble multi-page account updates into complete payloads before processing them.

Account replay

Account replay is split into two shapes:
  • createAccountReplay for one account address.
  • createAccountsByOwnerReplay for owner-scoped indexing with backfill, live updates, and reconnect handling.
Both rely on AccountView, ListAccounts, GetAccount, and StreamAccountUpdates types from @thru/proto.

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

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());
}