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
backfill() and watch() async generators.
backfill
Stream historical blocks within a range.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 cancellationretry- Retry configuration
watch
Stream new blocks with reorg detection.fromBlock- Start watching from this block (default: current)include- Content level:'header'|'transactions'|'receipts'pollingInterval- Poll interval in ms (default: 1000)signal- AbortSignal for cancellationretry- 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:| Level | Data | Use Case |
|---|---|---|
'header' | Block headers only | Chain monitoring |
'transactions' | Headers + full transactions | Transaction indexing |
'receipts' | Headers + transactions + receipts | Event indexing |
Reorg Detection
BlockStream tracks the parent hash chain to detect reorganizations:- Block number regression - Block number goes backward
- Parent hash mismatch - New block’s parent doesn’t match last known block
- 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
- Block - Block type definition
- BlockHeader - Block header details
- EventStream - Contract event streaming

