Skip to main content
Indexing turns on-chain events into data your application can react to: balance updates, transaction history, UI notifications. This guide shows how to subscribe to events from a deployed Stable contract using ethers.js and how to backfill historical events so you don’t miss any emitted while your service was offline.

Prerequisites

  • A deployed contract on Stable testnet or mainnet. If you need one, see Deploy and Verify.
  • Node.js 20 or later.
  • The contract address and the ABI of the events you want to index.

1. Install and configure

2. Subscribe to live events

Use a WebSocket provider so you receive events as soon as validators finalize each block. WebSocket avoids polling overhead and keeps notification latency close to block time (~0.7 seconds on Stable).
Events arrive in real time as callers invoke your contract.

3. Backfill historical events

When a service starts, you usually need to catch up on events emitted while it was offline. Use queryFilter with a block range.
Wide block ranges (millions of blocks) can exceed RPC rate limits and time out. For production indexers, paginate by 10k-block windows or use Stablescan’s Etherscan-compatible API for indexed historical queries.

4. Filter events by indexed arguments

Events with indexed parameters (like caller above) can be filtered server-side. Pass the filter value instead of reading every event and filtering in your app.

Handle connection drops

WebSocket connections can drop. For production indexers, implement reconnection logic so you don’t miss events.

Track unbonding completions

Index system transaction events (unbonding completions) emitted by the protocol.

Build a P2P payment app

Apply indexing to USDT0 Transfer events and build a payment history view.

JSON-RPC reference

See which eth_getLogs and related methods Stable supports.
Last modified on April 23, 2026