In this recipe we’ll show you how to use the Codex api to fetch a list of swaps for a token, complete with filtering, sorting, and realtime updates.
This data powers the transactions tables view on Defined.fi.

Queries
To get a list of swaps for a token, you can use thegetTokenEvents query.
For example, for the WBNB token on the BNB chain (networkId 56), you can use the following query:
Swaps
Swaps
cursor argument to get the next page of results.
Modify the query to include the cursor like this:
Paginated
Paginated
getTokenEventsForMaker, holders for an example.
Realtime Updates
To get realtime updates, you can use theonTokenEventsCreated subscription.
Subscription
Subscription
Now you’ve got all you need to build a fully functional swap list view.
See more event queries in the api reference, like getTokenEventsForMaker, getEventLabels for an example.
And more subscriptions like