Prior to executing any swap or bridging, you need to request the best route from our smart routing API.
The LI.FI SDK provides functionality to request routes and quotes, as well as to execute them. This guide will walk you through the process of making a request using getRoutes
and getQuote
functions.
To get started, here is a simple example of how to request routes to bridge and swap 10 USDC on Arbitrum to the maximum amount of DAI on Optimism.
When you request routes, you receive an array of route objects containing the essential information to determine which route to take for a swap or bridging transfer. At this stage, transaction data is not included and must be requested separately. Read more Execute Routes/Quotes.
Additionally, if you would like to receive just one best option that our smart routing API can offer, it might be better to request a quote using getQuote
. See #request-a-quote section.
The getRoutes
function expects a RoutesRequest
object, which specifies a desired any-to-any transfer and includes all the information needed to calculate the most efficient routes.
Below are the parameters for the RoutesRequest
interface along with their descriptions:
fromChainId
(number, required)The ID of the source chain (e.g., Ethereum mainnet is 1).
fromTokenAddress
(string, required)The contract address of the token on the source chain. Ensure this address corresponds to the specified fromChainId
.
fromAmount
(string, required)The amount to be transferred from the source chain, specified in the smallest unit of the token (e.g., wei for ETH).
fromAddress
(string, optional)The address from which the tokens are being transferred.
toChainId
(number, required)The ID of the destination chain (e.g., Optimism is 10).
toTokenAddress
(string, required)The contract address of the token on the destination chain. Ensure this address corresponds to the specified toChainId
.
toAddress
(string, optional)The address to which the tokens will be sent on the destination chain once the transaction is completed.
fromAmountForGas
(string, optional)Part of the LI.Fuel. Allows receiving a part of the bridged tokens as gas on the destination chain. Specified in the smallest unit of the token.
options
(RouteOptions, optional)Additional options for customizing the route. This is defined by the RouteOptions
interface (detailed below, see #route-options).
The RouteOptions
interface allows for further customization of the route request. Below are the parameters for the RouteOptions
interface along with their descriptions:
integrator
(string, optional)The identifier of the integrator, usually the dApp or company name. Ideally, this should be specified when configuring the SDK, but it can also be modified during a request. See Configure SDK.
fee
(number, optional)The integrator fee percentage (e.g., 0.03 represents a 3% fee). This requires the integrator to be verified.
As an integrator, you can monetize your LI.FI SDK integration and collect fees. See Monetization / Take Fees for more information.
maxPriceImpact
(number, optional)Hides routes with a price impact greater than or equal to this value. (e.g., 0.3 represents 30%)
order
(string, optional)Default: RECOMMENDED
The order preference for routes:
RECOMMENDED
This sorting option balances cost and complexity, prioritizing affordable and less complex routes. It first sorts routes based on their cost and then focuses on the top 5% of the routes. These top routes are ranked by considering both their cheapness and ease of use.
FASTEST
This sorting option prioritizes routes with the shortest estimated execution time. Users who value speed and want their transactions to be completed as quickly as possible should choose the fastest routes.
slippage
(number, optional)Default: 0.03
The slippage tolerance, expressed as a decimal proportion (e.g., 0.03 represents 3%).
referrer
(string, optional)The wallet address of the referrer, for tracking purposes.
allowSwitchChain
(boolean, optional)Default: false
Specifies whether to return routes that require chain switches (2-step routes).
allowDestinationCall
(boolean, optional)Default: true
Specifies whether destination calls are enabled.
bridges
(AllowDenyPrefer, optional)An AllowDenyPrefer
object to specify preferences for bridges.
exchanges
(AllowDenyPrefer, optional)An AllowDenyPrefer
object to specify preferences for exchanges.
The AllowDenyPrefer
interface is used to specify preferences for bridges or exchanges. Using the allow
option, you can allow tools, and only those tools will be used to find the best routes. Tools specified in deny
will be blocklisted.
You can find all available keys in List: Chains, Bridges, DEXs, Solvers or get the available option from the API. See Chains and Tools.
Below are the parameters for the AllowDenyPrefer
interface:
allow
(string[], optional)A list of allowed bridges or exchanges (default: all).
deny
(string[], optional)A list of denied bridges or exchanges (default: none).
prefer
(string[], optional)A list of preferred bridges or exchanges (e.g., ['1inch']
to prefer 1inch if available).
When you request a quote, our smart routing API provides the best available option. The quote includes all necessary information and transaction data required to initiate a swap or bridging transfer.
Here is a simple example of how to request a quote to bridge and swap 10 USDC on Arbitrum to the maximum amount of DAI on Optimism.
The getQuotes
function expects a QuoteRequest
object. RoutesRequest
and QuoteRequest
have some similarities and slight differences, and below, you can find a description of the QuoteRequest
interface's parameters.
fromChain
(number, required)The ID of the source chain (e.g., Ethereum mainnet is 1).
fromToken
(string, required)The contract address of the token on the source chain. Ensure this address corresponds to the specified fromChain
.
fromAmount
(string, required)The amount to be transferred from the source chain, specified in the smallest unit of the token (e.g., wei for ETH).
fromAddress
(string, required)The address from which the tokens are being transferred.
toChain
(number, required)The ID of the destination chain (e.g., Optimism is 10).
toToken
(string, required)The contract address of the token on the destination chain. Ensure this address corresponds to the specified toChain
.
toAddress
(string, optional)The address to which the tokens will be sent on the destination chain once the transaction is completed.
fromAmountForGas
(string, optional)Part of the LI.Fuel. Allows receiving a part of the bridged tokens as gas on the destination chain. Specified in the smallest unit of the token.
In addition to the parameters mentioned above, all parameters listed in the#route-options section are also available when using getQuote
, except for allowSwitchChain
, which is used exclusively to control chain switching in route requests.
Also, parameters to specify options for allowing, denying, or preferring certain bridges and exchanges have slightly different names:
allowBridges
(string[], optional)
denyBridges
(string[], optional)
preferBridges
(string[], optional)
allowExchanges
(string[], optional)
denyExchanges
(string[], optional)
preferExchanges
(string[], optional)
Besides requesting general quotes, the LI.FI SDK also provides functionality to request quotes for destination contract calls.
Read more xChain Zaps.
Here is a simple example of how to request a quote to bridge and purchase an NFT on the OpenSea marketplace costing 0.0000085 ETH on the Base chain using ETH from Optimism. The call data for this example was obtained using the OpenSea Seaport SDK.
The getContractCallsQuote
function expects a ContractCallsQuoteRequest
object, which includes all the information needed to request a quote for a destination contract call.
Contract call quote request can be treated as an extension to the quote request and in addition to the parameters mentioned below, all parameters listed in the #other-quote-parameters section (such as integrator
, fee
, slippage
, etc.) are also available when using getContractCallsQuote
.
fromChain
(number, required)The ID of the source chain (e.g., Ethereum mainnet is 1).
fromToken
(string, required)The contract address of the token on the source chain. Ensure this address corresponds to the specified fromChain
.
fromAddress
(string, required)The address from which the tokens are being transferred.
toChain
(number, required)The ID of the destination chain (e.g., Optimism is 10).
toToken
(string, required)The token required to perform the contract interaction (can be something to stake, donate, or to be used as payment). Ensure this address corresponds to the specified toChain
.
toAmount
(string, required)The amount of tokens required by the contract interaction. The LI.FI API will try and generate a quote that guarantees at least that amount on the destination chain.
toFallbackAddress
(string, optional)The address to send the bridged tokens to if the call fails. Defaults to the sending address if not specified.
contractCalls
(ContractCall[], required)Array of contract call objects.
fromAmount
(string, required): The amount of tokens to be sent to the contract. This amount is independent of any previously bridged or deposited tokens.
fromTokenAddress
(string, required): The address of the token to be sent to the contract. For example, an ETH staking transaction would require ETH.
toContractAddress
(string, required): The address of the contract to interact with on the destination chain.
toContractCallData
(string, required): The call data to be sent to the contract for the interaction on the destination chain.
toContractGasLimit
(string, required): The estimated gas required for the contract call. Incorrect values may cause the interaction to fail.
toApprovalAddress
(string, optional): The address to approve the token transfer if it is different from the contract address.
toTokenAddress
(string, optional): The address of the token that will be output by the contract, if applicable (e.g., staking ETH produces stETH).
contractOutputsToken
(string, optional)The token address that will be output by the contract, if applicable. Omit if no token should be returned.
Route
and Quote
Even though Route
and Quote
terms lie in the same field of providing you with the best option to make a swap or bridging transfer, there are some differences you need to be aware of.
A Route
in LI.FI represents a detailed transfer plan that may include multiple steps. Each step corresponds to an individual transaction, such as swapping tokens or bridging funds between chains. These steps must be executed in a specific sequence, as each one depends on the output of the previous step. A Route
provides a detailed pathway for complex transfers involving multiple actions.
In contrast, a Quote
is a single-step transaction. It contains all the necessary information to perform a transfer in one go, without requiring any additional steps. Quotes
are used for simpler transactions where a single action, such as a token swap or a cross-chain transfer, is sufficient. Thus, while Routes
can involve multiple steps to complete a transfer, a Quote
always represents just one step.
Read more LI.FI Terminology.