---
title: "@thru/replay"
description: Historical plus live replay library for ordered block, transaction,
  account, and event streams.
source_url:
  html: https://thru.org/docs/sdks/web-packages/replay/
  md: https://thru.org/docs/sdks/web-packages/replay.md
---

# @thru/replay

`@thru/replay` turns chain RPC backfill plus live streaming into a single ordered feed.

## Install

```bash
npm install @thru/replay @thru/sdk
```

## 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`](https://thru.org/docs/sdks/web-packages/indexer.md)
- you need a full app-facing RPC SDK instead of replay primitives: use [`@thru/sdk`](https://thru.org/docs/sdks/web-packages/sdk.md)

## Entry Point

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

## 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

- 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.

The replay package depends on generated protobuf types from `@thru/sdk/proto` internally.

## 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

```ts
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

- [Indexing Overview](https://thru.org/docs/indexing/overview.md) for package selection and the full indexing guide structure.
- [Build an Indexer](https://thru.org/docs/indexing/build-an-indexer.md) for a step-by-step guide using `@thru/indexer` on top of replay.
- [`@thru/indexer`](https://thru.org/docs/sdks/web-packages/indexer.md) for persistence and checkpoints built on replay.
- [`@thru/sdk`](https://thru.org/docs/sdks/web-packages/sdk.md) for the full app-facing RPC client.
