🟢Integration Guide
Welcome to the Butter Smart Router service! This document will guide developers on how to integrate our service into their applications to facilitate querying the best route from token1 on Chain A to token2 on Chain B and assembling transactions.
API Interface Overview
Butter Smart Router service provides the following interfaces:
Query Supported Chain Info List
Interface:
/supportedChainInfoDescription: Query the list of all supported chains by this service.
Query Supported Token List
Interface:
/supportedTokenListDescription: Query supported tokens for every chain or for one specified chain.
Find Token Information
Interface:
/findTokenDescription: Find the token information by the given address.
Query Best Routes
Interface:
/routeDescription: Query the best routes from token1 on Chain A to token2 on Chain B.
Assemble Transaction Data Based on Selected Route
Interface:
/swapDescription: Assemble transaction data based on the selected route.
Authentication
All endpoints of the Butter Smart Router service support (and recommend) API Key authentication. When authenticating, include the following two headers on every request:
x-api-key-id
<your-api-key-id>
The identifier of your API key.
Authorization
Bearer <your-api-secret>
The secret paired with your API key.
Note: API Key authentication is currently optional. Requests without an API Key are still accepted but subject to strict rate limiting, and will be rejected after a transition period. For production use, please apply for an API Key from Butter Network.
API Key credentials are issued by the Butter team. Please contact us to apply for your credentials (the same way you apply for a dedicated entrance). The examples below use placeholders <your-api-key-id> and <your-api-secret> — replace them with your own credentials.
curl example
TypeScript example
The same headers work for every routing endpoint (/route, /swap, /supportedChainInfo, /supportedTokenList, /findToken, etc.):
Integration Steps
1. Query Supported Chain Info
Use the /supportedChainInfo interface to query the list of all supported chains by this service. You will receive a list of blockchains' information.
Request Url with GET method:
Response:
Note: the chain info list may change over time as new chains are added or removed from the Butter Router's support, please request this endpoint to get the latest supported chain info.
2. Query Supported Token List
Use the /supportedTokenList interface to query the tokens supported by the Butter Router. Omit chainId to get one token group for every supported chain, or provide a supported chain ID to get a single group.
Request URLs with GET method:
Response:
The response always groups tokens by chain. A filtered request still returns data as an array with one group, and an unfiltered request keeps supported chains whose tokens array is empty. See the GET /supportedTokenList reference for the complete field and error definitions.
3. Find Token Information
Use the /findToken interface to find the token information by the given address. The result is a list of token information because same token address may exist on different blockchains.
E.g, find the token information by the address 0x55d398326f99059fF775485246999027B3197955.
Request Url with GET method:
Response:
4. Query Best Routes
Use the /route interface to query the best routes from token1 on Chain A to token2 on Chain B. These routes are sorted by totalAmountOut of token2 in descending order.
E.g. find the best swap route from 1 ETH on Ethereum to USDT on BSC with 1% slippage and Butter+ as the entrance.
Request URL with GET method:
Success Response:
Failure Response:
5. Assemble Transaction Data Based on Selected Route
Use the /swap interface to assemble transaction data based on the selected route hash from the /route response.
E.g. assemble the transaction data based on the route hash 0x4cae26ffe044267ffa39f5885259c104abd67bec07a1452169dbc4fff5d0319c with the slippage of 1% and the sender address 0x2D4C407BBe49438ED859fe965b140dcF1aaB71a9 and the receiver address 0x2D4C407BBe49438ED859fe965b140dcF1aaB71a9.
Request URL with GET method:
Success Response:
Failure Response:
Note:
the route data will be expired after 5 minutes, so it is recommended to request the
/routeinterface periodically to get the best route and then assemble the transaction data.if the source token is an ERC20 token, the user needs to approve the router contract to spend the token before calling the swap function. The router contract address is the to field in the swap response.
6. Send swap transaction
To send the swap transaction to source blockchain, you can use the information from the /swap response. Here are some examples for different blockchain networks.
Common EVM Chains (Ethereum, BSC, Polygon, etc.)
Tron
Solana
Bitcoin
Here is the example using OKX injected provider.
Last updated