Skip to main content
This guide builds an alert feed with the multi-events stream. It sends you every trade on Ethereum and Base that is worth $100,000 or more, or that was sent by a wallet on your watch list. It shows the token symbols, works out whether each trade was a buy or a sell, and resumes after a disconnect without missing trades. You need Node.js 22 or later (for the built-in WebSocket), or Python 3 with the websockets package.

1. Choose the subscription

  • chains uses the evm:<chainId> form. Bare numbers are rejected.
  • swap-enriched adds baseTokenData and quoteTokenData with name, symbol, decimals and logo, so you don’t need a separate token lookup. It contains every field of swap, so there is no reason to request both.
  • tokenAmountUsd checks the trade’s amountUSD. Comparisons need a JSON number, not a string.
  • sender checks the trade’s initiator: the wallet that sent the transaction. Up to 500 wallets fit in one in list.
See Subscribing and Filters for every option.

What it costs

The connection budget is 100 cost units. This subscription has two pairs, swap-enriched|evm:1 and swap-enriched|evm:8453, and each costs 10, for a total of 20. Each pair is chain-wide because of the or. A filter that only names wallets would cost 1 per pair, since the server only has to look at those wallets’ trades. But the gte branch doesn’t name any address, so the server must check every trade on the chain against the threshold, and an or with one such branch is chain-wide as a whole. Splitting it into two subscriptions doesn’t make it cheaper: a threshold subscription costs 2 × 10 = 20 and a wallet subscription 2 × 1 = 2, total 22. Split it only if you want each rule under its own subscription id. Adding the plain swap kind would double the cost to 40. See Limits and subscription cost.

2. Read the trades

Each match arrives as an event. With two pairs, the event has a pair field and a cursor:
The payload has no buy or sell field. Work it out from the base token’s raw amount: positive means the token went into the pool, so the trader sold it; otherwise the trader bought it. Then:
  • Amount: the absolute value of amount0 or amount1 on the base token’s side.
  • Price: baseTokenData.priceUSD, which is the price at this trade. If baseTokenData is null, use priceUSD0 or priceUSD1.
  • USD value: amountUSD.
  • Symbol: baseTokenData.symbol. Token data can be null when the token isn’t known yet or the lookup was slow, so fall back to the address.
The example above reads: Ethereum: 0x6121…4895 bought 71.43 WETH for $250,000 at $3,500. See Event payloads for every field.

3. Keep cursors and resume

Store the newest cursor of each pair. Cursors arrive in three places:
  • subscribed has a cursors map with the starting cursor of each pair.
  • Every event has a cursor for its pair.
  • Every 30 seconds, a cursor message moves each pair forward, even when nothing matched. A rare filter like this one depends on these checkpoints to resume after a quiet period.
After a disconnect, subscribe again with the same params and a since map:
The server replays the matching trades you missed, then continues live with no duplicates. History is kept for about 10 minutes. If a cursor is older, the whole subscription is refused with RESUME_EXPIRED, and details.pairs lists the expired pairs. Drop those pairs from since and subscribe again. See Cursors and resuming.

Full example

The client below prints alerts, saves cursors to cursors.json so it can resume after a restart, and reconnects with backoff.
The example saves after every message to keep it short. In production, save every few seconds or on shutdown; at worst you replay a few alerts you already handled. Deduplicate by hash and logIndex if that matters. If you change the chains or event kinds, delete the saved cursors for pairs that no longer exist. Sending a pair the new params don’t produce fails with Unknown pairs in since.

Optional: backfill a gap or an expired resume

Two situations leave holes in the feed:
  • A gap message: the stream skipped the listed blocks on that chain, inclusive, and won’t send their trades.
  • RESUME_EXPIRED: you were disconnected for longer than the stream’s history.
GET /trades reads trades from storage and can fill a hole when you know which token or pool to look at. It takes a token or pool address, a chain, and a time window in Unix milliseconds (from, to), not block numbers. Use the timestamp of your last trade before the hole and of the first one after it.
  • Pages hold up to 100 trades. For the next page, pass the cursor of the last trade with the same query, and stop when a page has fewer than limit trades.
  • The REST trade shape differs from the stream payload: it is oriented to one token and has tokenAmountUsd, type (buy or sell) and sender fields. Apply your threshold and wallet list to those fields.
  • For a token address, only the token’s two most active pools are searched. Query by pool address when you can.
There is no REST endpoint that lists all trades of a chain or all trades of a wallet, so a chain-wide threshold or a wallet list can’t be fully backfilled. Keep your client connected and resume within the history window to avoid holes.