Migration guide for upgrading LI.FI SDK v2 to v3
LI.FI SDK v3 has undergone a major update, improving compatibility with popular libraries like Viem and adding new features, including support for multiple ecosystems, starting with Solana. Consequently, as detailed in this guide, you need to be aware of some breaking changes and deprecations. We also recommend reviewing the updated documentation for additional new features not covered here.
To get started, install the latest version of LI.FI SDK.
We have made significant changes to how the LI.FI SDK is configured. It is no longer class-based, so you don't need to create, maintain, and share a LiFi class instance to use SDK functionality. Instead, it is now function-based, allowing you to configure it once and update the configuration from any place without needing to maintain or share the configuration object's reference. You can simply import the necessary functions from the package wherever needed. Read more Configure SDK
In this example, you can call the getQuote
function from anywhere using SDK v3, whereas with SDK v2, you had to share a created LiFi
class instance and call getQuote
as a method of that class.
Due to these changes, the configuration-related functions from the LiFi
interface are no longer needed. The previous interface included:
Now, you can import the configuration object directly and make any necessary changes to it. This simplifies the process and improves code maintainability. Read more #update-sdk-configuration.
All methods previously supported by the class-based approach are now individual functions that you can import directly from the @lifi/sdk
package. Some of these methods have been renamed to better reflect their functionality or to have a more concise name.
getContractCallQuote
-> getContractCallsQuote
getTokenApproval
-> getTokenAllowance
bulkGetTokenApproval
-> getTokenAllowanceMulticall
approveToken
-> setTokenAllowance
moveExecutionToBackground
-> updateRouteExecution
See #request-contract-call-quote, #manage-route-execution and Token Management for more details.
Since the first version of the LI.FI SDK, we have relied on the Ethers.js
library for all EVM-related interactions. However, as the industry evolves, Viem
is gaining wide adoption and starting to replace Ethers.js
.
To ensure our product remains robust and future-proof, we have decided to transition our entire stack to a more reliable solution - Viem
(Wagmi
for the Widget).
Please see the Ethers v5 → viem Migration Guide for more details. Among other notable changes, this transition also replaces all BigNumber utilities we previously used in v2 with the native bigint
primitive.
LI.FI SDK v3 now supports two ecosystems — EVM and Solana — with more on the way. To accommodate these new ecosystems, we have introduced the concept of ecosystem providers in SDK v3. We extracted all EVM-related functionality from SDK v2 and integrated it into an EVM provider. Additionally, a Solana provider has been added to enable Solana-related functionality across all SDK functions.
These ecosystem providers are designed with modularity in mind and are fully tree-shakable, ensuring that they do not add unnecessary weight to your bundle if not used.
Previously, it was necessary to pass an Ethers.js
Signer object to executeRoute
and other functions for EVM interactions. With the introduction of ecosystem providers, you only need to configure them once when setting up the SDK. After that, you can use executeRoute
and other functions without passing any additional options. The SDK will automatically determine the appropriate ecosystem provider and notify you if no suitable provider is configured.
Read more #introduction-to-sdk-ecosystem-providers.
Check out our complete examples in the SDK repository, and feel free to file an issue if you encounter any problems.
For a detailed view of all the changes, please see the CHANGELOG.