Package Exports
- @lifi/sdk
- @lifi/sdk/package.json
Readme
LI.FI SDK
LI.FI SDK provides a powerful toolkit for developers to enable seamless cross-chain and on-chain swaps and bridging within their applications. Our JavaScript/TypeScript SDK can be implemented in front-end or back-end environments, allowing you to build robust UX/UI around our advanced bridge and swap functionalities. LI.FI SDK efficiently manages all communications between our smart routing API and smart contracts and ensures optimal performance, security, and scalability for your cross-chain and on-chain needs.
LI.FI SDK features include:
- Modular architecture - Install only the provider packages you need for your supported blockchain ecosystems (EVM, Solana, Bitcoin, Sui, Tron)
- All ecosystems, chains, bridges, exchanges, and solvers that LI.FI supports
- Complete functionality covering full-cycle from obtaining routes/quotes to executing transactions
- Easy tracking of the route and quote execution through the robust event and hooks handling
- Highly customizable settings to tailor the SDK to your specific needs including configuration of RPCs and options to allow or deny certain chains, tokens, bridges, exchanges, solvers
- Supports widely adopted industry standards, including EIP-5792, ERC-2612, EIP-712, and Permit2
- SDK ecosystem providers are based on industry-standard libraries (Viem for EVM, Solana Kit for Solana, Bigmi for Bitcoin, Mysten Sui SDK for Sui, TronWeb for Tron)
- Support for arbitrary contract calls on the destination chain
- Designed for optimal performance with tree-shaking and dead-code elimination, ensuring minimal bundle sizes and faster page load times in front-end environments
- Compatibility tested with Node.js and popular front-end tools like Vite
Installation
The LI.FI SDK follows a modular architecture. Install the core SDK package and the provider packages for the blockchain ecosystems you need:
Core SDK
pnpm add @lifi/sdkor
npm install --save @lifi/sdkProvider Packages
Install provider packages based on the blockchain ecosystems you want to support:
EVM Chains (Ethereum, Polygon, Arbitrum, Optimism, etc.)
pnpm add @lifi/sdk-provider-ethereumSolana
pnpm add @lifi/sdk-provider-solanaBitcoin
pnpm add @lifi/sdk-provider-bitcoinSui
pnpm add @lifi/sdk-provider-suiTron
pnpm add @lifi/sdk-provider-tronArchitecture
The LI.FI SDK uses a modular provider architecture:
@lifi/sdk- Core SDK package containing shared functionality, actions, and execution logic- Provider packages - Ecosystem-specific packages that handle wallet interactions and transaction execution for different blockchain types
This architecture allows you to:
- Install only the providers you need, reducing bundle size
- Use ecosystem-specific libraries optimized for each blockchain
- Maintain clean separation between core SDK logic and blockchain-specific implementations
Quick Start
Set up the SDK
Create SDK config with your integrator string and configure the providers for the blockchain ecosystems you want to support.
For EVM chains:
import { createClient } from '@lifi/sdk'
import { EthereumProvider } from '@lifi/sdk-provider-ethereum'
import { createWalletClient, http } from 'viem'
import { mainnet } from 'viem/chains'
// Add your account (e.g. privateKeyToAccount, mnemonicToAccount)
const walletClient = createWalletClient({
account,
chain: mainnet,
transport: http(),
})
const client = createClient({
integrator: 'Your dApp/company name',
providers: [
EthereumProvider({
getWalletClient: () => Promise.resolve(walletClient),
}),
],
})For multiple ecosystems:
import { createClient } from '@lifi/sdk'
import { EthereumProvider } from '@lifi/sdk-provider-ethereum'
import { SolanaProvider } from '@lifi/sdk-provider-solana'
import { BitcoinProvider } from '@lifi/sdk-provider-bitcoin'
import { SuiProvider } from '@lifi/sdk-provider-sui'
import { TronProvider } from '@lifi/sdk-provider-tron'
const client = createClient({
integrator: 'Your dApp/company name',
providers: [
EthereumProvider({ /* options */ }),
SolanaProvider({ /* options */ }),
BitcoinProvider({ /* options */ }),
SuiProvider({ /* options */ }),
TronProvider({ /* options */ }),
],
})Request a Quote
Now you can interact with the SDK and for example request a quote.
import { ChainId, getQuote } from '@lifi/sdk'
const quote = await getQuote(client, {
fromAddress: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045',
fromChain: ChainId.ARB,
toChain: ChainId.OPT,
fromToken: '0x0000000000000000000000000000000000000000',
toToken: '0x0000000000000000000000000000000000000000',
fromAmount: '1000000000000000000',
})Examples
See examples folder in this repository.
Documentation
Please checkout the SDK documentation and our API reference for further information.
Changelog
The changelog is regularly updated to reflect what's changed in each new release.