Overview
getSwapTokens returns the tokens that can be swapped on one network. Without a search, it returns a curated list of popular tokens for that network, such as the native token and major stablecoins. With a search, it returns only the tokens that match, with curated tokens first.
Use the result to build a token picker, then pass the chosen token’s address to getSwapQuote. A listed token can be swapped on that network, but a specific pair is not guaranteed: the quote is the final check, because routes depend on liquidity and amount.
Usage
Parameters
Use
getSwapChains to find the chain and networkId values that support swaps.
Returns
Promise<SwapTokensResponse>: an object with a tokens array. Each entry is a SwapCatalogToken:
tokens is an empty array when nothing matches the search, when the network has no swappable tokens, or when no swap provider is available for your environment or the user’s region.
Errors
Other failures keep their original error. These include an invalid
chain, a search longer than 256 characters, and network timeouts.
Examples
Search for a token
Search by symbol, name, or a pasted token address. Debounce the search in your UI, so a request is not sent on every keystroke.Convert an amount for the quote
getSwapQuote takes amounts in the token’s smallest unit, so use the token’s decimals to convert the user’s input.
React
useGetSwapTokens returns the same list in data. It stays disabled until both chain and networkId are defined, so you can pass them before the user picks a network.
Related
getSwapChains: list the networks that support swapsgetSwapQuote: quote a swap between two tokens- Building a swap UI: a full swap flow