Skip to main content

Overview

BlockStream provides robust block streaming with reorg detection. Inspired by Reth’s ExEx pattern, it tracks the chain state and emits events when blocks are added or removed due to reorganizations.

API

Factory

Returns an instance with backfill() and watch() async generators.

backfill

Stream historical blocks within a range.
Options:
  • fromBlock - Start block (inclusive, required)
  • toBlock - End block (inclusive, required)
  • include - Content level: 'header' | 'transactions' | 'receipts'
  • chunkSize - Blocks per batch (default: 100)
  • signal - AbortSignal for cancellation
  • retry - Retry configuration

watch

Stream new blocks with reorg detection.
Options:
  • fromBlock - Start watching from this block (default: current)
  • include - Content level: 'header' | 'transactions' | 'receipts'
  • pollingInterval - Poll interval in ms (default: 1000)
  • signal - AbortSignal for cancellation
  • retry - Retry configuration

Event Types

BlocksEvent

New canonical blocks added to the chain.

ReorgEvent

Chain reorganization detected.

LightBlock

Minimal block info for reorg tracking.

Include Levels

Control how much block data to fetch:

Reorg Detection

BlockStream tracks the parent hash chain to detect reorganizations:
  1. Block number regression - Block number goes backward
  2. Parent hash mismatch - New block’s parent doesn’t match last known block
  3. Deep reorg - Reorg extends beyond tracked history (throws UnrecoverableReorgError)

Consumer-Side Finality

BlockStream doesn’t track finality internally. Implement finality tracking yourself:

Error Handling

See Also