Skip to main content
Contracts emit events to record what happened, such as a token transfer. This recipe watches Transfer events from USDC on Sei Mainnet as they happen. Then it fetches past Transfer events. USDC is busy, so new events usually arrive within a minute.

Pick the right endpoint

Sei’s public endpoints split the work:
Watch live events over WebSocket. The public WebSocket endpoints do not serve eth_getLogs, so fetch past events over HTTP. Watchers that poll the public HTTP endpoints for new events can miss events or report them twice.

Install

Watch new events

Each script prints a line for every USDC transfer. The script keeps running until you stop it with Ctrl+C.
You are done when you see:
The scripts print the full sender and recipient addresses. They are shortened here. Sei has instant finality, so each event is final when it arrives. You do not need to wait for confirmations or handle reorganizations.
The web3.py example uses the subscription manager, which needs web3.py 7.7 or later.

Fetch past events

eth_getLogs returns the events in a block range. On the public endpoints, one request can cover at most 2,000 blocks. A larger range fails with block range too large. This example fetches the transfers from the latest 1,000 blocks.
You are done when you see:
To cover a longer range, split it into windows of 2,000 blocks or fewer and request them one after another. For a full history of a contract, use an indexer instead of eth_getLogs.