Introduction to SDK Ecosystem Providers
The LI.FI SDK supports different blockchain ecosystems, allowing you to integrate with EVM and Solana networks, with more ecosystems on the way. Internally, providers act as abstractions for each ecosystem, handling crucial tasks such as address resolution, balance checking, and transaction handling during route/quote execution. 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. The SDK offers four providers,EVM
, Solana
, UTXO
and Sui
, each with similar configuration options respective to their ecosystems.
Different types of wallets/accounts
To execute quotes/routes via a specific provider, that provider must be capable of signing transactions. SDK providers support signing transactions over the following types of wallets/accounts:- Local Accounts (e.g. private key/mnemonic wallets).
- JSON-RPC Accounts (e.g. Browser Extension Wallets, WalletConnect, etc.).
window.ethereum
, and managing the user’s account within the browser or mobile context. This setup is popular among dApps UIs and is often used together with libraries like Wagmi
, @solana/web3.js
, or @mysten/dapp-kit
.
These account types and interaction methods allow developers to choose the most suitable approach for integrating the SDK with their applications.
Setup EVM Provider
The EVM provider execution logic is built based on theViem
library, using some of its types and terminology.
Options available for configuring the EVM provider:
-
getWalletClient
: A function that returns aWalletClient
instance. -
switchChain
: A hook for switching between different networks.
Local Accounts
When using local accounts, developers need a predefined list of chains they plan to interact with in order to switch chains during transaction execution. These chains can be either from theviem/chains
package or fetched from LI.FI API and adopted to viem’s Chain
type.
Here’s a basic example using chains from viem/chains
:
JSON-RPC Accounts
The best way to interact with JSON-RPC accounts and passWalletClient
to the EVM
provider is to use the Wagmi library. Developers can configure Wagmi chains either by using chains from the viem/chains
package or fetching chains from LI.FI API and adapting them to Viem’s Chain
type.
Below is a simplified example of how to set up the EVM provider using chains from the LI.FI API in conjunction with Wagmi and React.
We provide a useSyncWagmiConfig
hook that synchronizes fetched chains with the Wagmi configuration and updates connectors. Please note that we do not initialize the Wagmi configuration with connectors. Additionally, we set reconnectOnMount
to false
since the reconnect
action will be called within useSyncWagmiConfig
hook after the chains are synchronized with the configuration and connectors.
Update provider configuration
Additionally, providers allow for dynamic updates to its initial configuration via thesetOptions
function.
Here’s an example of how to modify the initial configuration for EVM
provider:
Support for Ethers.js and other alternatives
Developers can still use Ethers.js or any other alternative Web3 library in their project and convertSigner
/Provider
objects to Viem’s WalletClient
before passing it to the EVM provider configuration.
Setup Solana Provider
The Solana provider execution logic is built based on the @solana/web3.js and @solana/wallet-adapter-base libraries, using some of its types and terminology. Options available for configuring the EVM provider:getWalletAdapter
: A function that returns a WalletAdapter instance.
Local Wallet Adapter
Standard Solana libraries do not offer a built-in method for creating a wallet adapter directly from a private key. To address this limitation, we provide theKeypairWalletAdapter
. This custom adapter enables users to create a wallet adapter from a private key.
It is worth noting that the KeypairWalletAdapter
is designed specifically for backend or testing purposes and should not be used in user-facing code to prevent the risk of exposing your private key.
JSON-RPC Wallet Adapter
To interact with JSON-RPC accounts and passWalletAdapter
to the Solana provider, we recommend using the @solana/wallet-adapter-base and @solana/wallet-adapter-react libraries. Unlike Wagmi, Solana configuration for React does not have global configurations. Therefore, we need to use React hooks to update the SDK configuration at runtime.
Below is a simplified example of how to set up the Solana provider.
Setup Sui Provider
The Sui provider execution logic is built based on the @mysten/dapp-kit and @mysten/sui libraries, using some of its types and terminology. Options available for configuring the Sui provider:getWallet
: A function that returns aWalletWithRequiredFeatures
instance (defined by@mysten/wallet-standard
).
JSON-RPC Wallet
To interact with user wallets (like Sui Wallet, Ethos, etc.) and passWalletWithRequiredFeatures
to the Sui provider, we recommend using the @mysten/dapp-kit library.
Below is a simplified example of how to set up the Sui provider with user wallets.
Setup UTXO (Bitcoin) Provider
The Bitcoin provider execution logic is built based on the Bigmi library, using some of its types and terminology. Options available for configuring the UTXO provider:getWalletClient
: A function that returns aClient
instance
JSON-RPC Wallet
To interact with user wallets like Phantom, Xverse, use thegetConnectorClient
action to return the Bigmi Client object required by the SDK.