Skip to main content
Source: poll.ts • Tests: poll.test.ts
This page is a placeholder. All examples on this page are currently AI-generated and are not correct. This documentation will be completed in the future with accurate, tested examples.

Polling

Poll operations until they succeed or timeout, with optional exponential backoff. Essential for waiting on asynchronous Ethereum operations like transaction confirmations, block finalization, or contract state changes.

Overview

Polling utilities provide:
  • Configurable intervals: Control polling frequency
  • Exponential backoff: Progressively longer intervals
  • Timeout handling: Fail after maximum duration
  • Validation: Custom success conditions
  • Progress callbacks: Monitor polling attempts

Basic Usage

Simple Polling

Poll until result is truthy:

With Validation

Poll until validation passes:

Poll Options

PollOptions

Polling Functions

poll

Core polling function with full configuration:

pollUntil

More expressive when checking specific conditions:

pollForReceipt

Convenience function for transaction receipts:

pollWithBackoff

Poll with exponential backoff enabled by default:

Exponential Backoff

How It Works

With backoff enabled, intervals increase exponentially:

Example Timeline

Configuration: { interval: 1000, backoffFactor: 1.5, maxInterval: 10000 }

When to Use Backoff

Use backoff when:
  • Operation may take progressively longer
  • Want to reduce server load over time
  • Waiting for finality (takes longer as confirmations increase)
Don’t use backoff when:
  • Need consistent check frequency
  • Time-sensitive operations
  • Known fixed interval required

Real-World Examples

Wait for Transaction

Wait for transaction confirmation with backoff:

Wait for Contract Deployment

Poll until contract code is deployed:

Wait for State Change

Poll contract state until condition met:

Wait for Block Number

Wait for specific block with progress:

Multiple Conditions

Poll until multiple conditions satisfied:

Combining with Other Utils

Poll with Retry

Retry each poll attempt:

Poll with Timeout Per Attempt

Add timeout to each poll attempt:

Poll with Rate Limiting

Rate limit polling attempts:

Error Handling

Handle Polling Errors

Errors during polling don’t stop the poll:

Validation Errors

Distinguish between errors and unmet conditions:

Best Practices

Choose Appropriate Intervals

  • Transaction receipts: 1000ms (typical block time ~12s)
  • Block numbers: 12000ms (matches block time)
  • Contract state: 2000-5000ms (depends on update frequency)
  • Off-chain data: 5000-10000ms (depends on API)

Set Reasonable Timeouts

  • Fast operations: 30000ms (30s)
  • Transaction confirmation: 120000ms (2 minutes)
  • Multi-block operations: 300000ms (5 minutes)

Use Backoff for Long Operations

Enable backoff when:
  • Operation may take minutes
  • Checking less frequently over time is acceptable
  • Want to reduce server load

Monitor Progress

Always use onPoll callback for observability:

API Reference

poll

pollUntil

pollForReceipt

pollWithBackoff

See Also