- Polling Swap events for all pairs
- Subscription using eth_subscribe (coming later - HIP-694)
Polling Swap events for all pairs
No gas cost — read-only call. Every time a user executes a swap, the contract emits a ‘Swap’ event with the updated reserve values for the token pair. The following code demonstrates how to listen to these ‘Swap’ events for all pairs using either the REST API or JSON RPC.When a swap involves multiple liquidity pairs, a successful smart contract call will emit multiple ‘Swap’ events. To determine the route used, as well as the initial input amount and the final output amount, aggregate all the ‘Swap’ event logs.
- JSON RPC
- REST API
Next steps
Track swap events (V1)
The V1 equivalent with reserve-style amounts.
Fetch all pools (V2)
Map pair addresses back to pools and tokens.