Migrating to LI.FI SDK v2

Migration guide of upgrading LI.FI's SDK v1 to v2
This migration guide is a quick reference to the upgrades/fixes in LI.FI's SDK v2. All the breaking changes, deprecations, improvements, etc, are listed below. We advise going through all the changes and updating the SDK implementation in your project accordingly.

🚨 Breaking Changes

Deprecation of getByChainID method

The method getByChainID is no longer available in the SDK, use ChainsService instead.
- const chainResponse = getChainById(Number(chainId));
+ import ChainsService from './ChainsService'
+ const chainService = ChainsService.getIns
+ const chainResponse = await chainService.getChainById(fromChainId)

Rename updateCallback method in settings

The method updateCallback is renamed to updateRouteHook
import { LiFi } from "@lifi/sdk"
const lifi = new LiFi(lifiConfig);
const routeUpdateCallback = () => { ... }
const executionSettings: ExecutionSettings = {
- updateCallback: routeUpdateCallback,
+ updateRouteHook: routeUpdateCallback
const response = await lifi.execute(signer, route, executionSettings);

Rename acceptSlippageUpdateHook callback method in settings

The method acceptSlippageUpdatehook is renamed to acceptExchangeRateUpdateHook.
const exchangeRateUpdateCallback = () => { ... }
const executionSettings: InternalExecutionSettings = {
- acceptSlippageUpdateHook: exchangeRateUpdateCallback,
+ acceptExchangeRateUpdateHook: exchangeRateUpdateCallback,

Add integrator during SDK initialisation

During the initialisation of the SDK, you should pass the integrator as part of the configuration object.
The configuration to instantiate LiFi is now mandatory.
import { Lifi } from '@lifi/sdk'
// Mandatory to pass the configuration object
const lifiConfig = {
integrator: "your-integrator-name"
const lifi = new LiFi(lifiConfig)
By providing the integrator during the initialisation of the SDK, it'll be included as request headers for all requests made by the SDK which would later be used for tracking and identification purposes on the server side.

Returning Promise instance of Route

Any route interaction to SDK would now return the initial Promise instance of Route created during the first execution of Route. In order to get more details about the Route, developer would need to resolve the Promise to access the information.

⚒️ Improvements

Add convertQuoteToRoute helper function to execute single-step quotes

For single-step executions a new helper function, convertQuoteToRoute is added to the SDK. This function takes a Step object as input and returns a Route object. It is useful for converting quotes to routes, which is necessary for executing transactions.
import { convertQuoteToRoute } from '@lifi/sdk';
import { LiFi } from '@lifi/sdk';
const lifi = new LiFi(lifiConfig);
const quoteWithSingleStep = await lifi.getQuote(quoteRequest);
// Use the convertQuoteToRoute function to convert the Step to a Route
const route: Route = convertQuoteToRoute(quoteWithSingleStep);
// Now, you can use the route object for executing transactions
const response = await lifi.executeRoute(route);

Add getConnections method to LI.FI SDK

A new method getConnections is added to the SDK, which retrieves available connections for swapping or bridging tokens. This function takes a ConnectionsRequest object as a parameter and returns a ConnectionsResponse object.
import { LiFi } from '@lifi/sdk';
const lifi = new LiFi(lifiConfig);
const request: ConnectionsRequest = {
fromChain: 1,
fromToken: '0x123456789abcdef',
toChain: 137,
toToken: '0x987654321fedcba',
allowBridges: ['connext', 'uniswap']
const connections = await lifi.getConnections(request);

Add support to modify Transaction Request

A new callback is added that allows developers to customise the gas configuration for the transaction request before sending the transaction to the blockchain.
The callback can be set in ExecutionSettings while interacting with the SDK.
import { LiFi } from '@lifi/sdk';
const lifi = new LiFi();
// define your logic for modifying the gas config of the transaction request
const updateGasConfig = async (txRequest: TxRequest): Promise<TxRequest> => {
const customGasConfig = await customGas();
const updatedTxRequest = {
return updatedTxRequest;
// add callback function to modify the gas configurations, in settings
const settings: ExecutionSettings = {
settings: {
updateTransactionRequestHook: updateGasConfig
const response = await lifi.executeRoute(signer, route, settings)
Only the modified gas config variable such as gasLimit, gasPrice, maxPriorityFeePerGas and maxFeePerGas are picked up from it.

Optimise Chain Switching in Bridging Steps

The update refines the executeStep function's chain-switching logic, allowing users to leave the source chain once the transaction is signed. Users now only need to switch to the destination chain if a swap is required, streamlining the bridging process and improving the user experience.


For a detailed view of all the changes please see the CHANGELOG