Skip to main content

Events

The events interface provides EventStream instances for robust event streaming with dynamic chunking, retry logic, and block context metadata.
This uses the Contract pattern - a copyable implementation you add to your codebase. EventStream itself is a library primitive.

Basic Usage

Filtering Events

Filter by indexed parameters when creating the stream:

Backfill Historical Events

Use backfill() to fetch events from a specific block range:

Dynamic Chunking

EventStream automatically handles large block ranges by chunking requests:
  • Starts with 100 blocks per request
  • Reduces chunk size by 50% on “block range too large” errors
  • Increases chunk size by 25% after 5 consecutive successes
  • Never goes below 10 blocks minimum

Watch for New Events

Use watch() to poll for new events:

Watch from Specific Block

Cancellation with AbortSignal

Use AbortSignal to cleanly stop streaming:

Backfill Then Watch

Combine backfill and watch for complete event history:

EventStreamResult Structure

Each yielded result contains the log and metadata:

Standalone EventStream

EventStream is a library primitive you can use directly:

Retry Configuration

Configure retry behavior for transient errors:

Error Handling