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.

This data powers the transactions tables view on Defined.fi.

Queries
To get a list of swaps for a token, you can use the
getTokenEvents query.For example, for the WBNB token on the BNB chain (networkId 56), you can use the following query:Swaps
Swaps
To get more (paginate), you can use the
cursor argument to get the next page of results.Modify the query to include the cursor like this:Paginated
Paginated
Now you know how to use a paginated cursor to fetch more results.This pattern is used in many places in the Codex API, see
getTokenEventsForMaker, holders for an example.Realtime Updates
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