<div align="center">

[![license](https://img.shields.io/github/license/lifinance/sdk)](/LICENSE)
[![npm latest package](https://img.shields.io/npm/v/@lifi/sdk/latest.svg)](https://www.npmjs.com/package/@lifi/sdk)
[![npm downloads](https://img.shields.io/npm/dm/@lifi/sdk.svg)](https://www.npmjs.com/package/@lifi/sdk)
[![Follow on Twitter](https://img.shields.io/twitter/follow/lifiprotocol.svg?label=follow+LI.FI)](https://twitter.com/lifiprotocol)

</div>

<h1 align="center">LI.FI SDK</h1>

[**LI.FI SDK**](https://docs.li.fi/sdk/overview) 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**](https://docs.li.fi/sdk/overview) features include:

- **Modular architecture** - Install only the provider packages you need for your supported blockchain ecosystems (EVM, Solana, Bitcoin, Sui, Tron, Stellar)
- All ecosystems, chains, bridges, exchanges, and solvers that [LI.FI](https://docs.li.fi/introduction/chains) 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](https://eips.ethereum.org/EIPS/eip-5792), [ERC-2612](https://eips.ethereum.org/EIPS/eip-2612), [EIP-712](https://eips.ethereum.org/EIPS/eip-712), and [Permit2](https://github.com/Uniswap/permit2)
- SDK ecosystem providers are based on industry-standard libraries ([Viem](https://viem.sh/) for EVM, [Solana Kit](https://github.com/anza-xyz/kit) for Solana, [Bigmi](https://github.com/lifinance/bigmi) for Bitcoin, [Mysten Sui SDK](https://github.com/MystenLabs/sui/tree/main/sdk) for Sui, [TronWeb](https://tronweb.network/) for Tron, [Stellar SDK](https://github.com/stellar/js-stellar-sdk) for Stellar)
- 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

```bash
pnpm add @lifi/sdk
```

or

```bash
npm install --save @lifi/sdk
```

### Provider Packages

Install provider packages based on the blockchain ecosystems you want to support.

Each provider bundles its ecosystem library, but you configure a provider by handing it a
wallet or client object that **you** construct — so install the ecosystem library alongside
the provider whenever you import from it in your own code:

**EVM Chains (Ethereum, Polygon, Arbitrum, Optimism, etc.)**
```bash
pnpm add @lifi/sdk-provider-ethereum viem
```

**Solana**
```bash
pnpm add @lifi/sdk-provider-solana @wallet-standard/base
```

**Bitcoin**
```bash
pnpm add @lifi/sdk-provider-bitcoin @bigmi/core
```

**Sui**
```bash
pnpm add @lifi/sdk-provider-sui @mysten/sui
```

**Tron**
```bash
pnpm add @lifi/sdk-provider-tron @tronweb3/tronwallet-abstract-adapter
```

**Stellar**
```bash
pnpm add @lifi/sdk-provider-stellar
```

`StellarProvider` takes a small `StellarWallet` interface the package defines itself, so it
needs no ecosystem library. To discover and connect browser wallets such as Freighter,
xBull, or Lobstr, we recommend
[Stellar Wallets Kit](https://github.com/Creit-Tech/Stellar-Wallets-Kit).

## Architecture

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:**
```ts
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:**
```ts
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'
import { StellarProvider } from '@lifi/sdk-provider-stellar'

const client = createClient({
  integrator: 'Your dApp/company name',
  providers: [
    EthereumProvider({ /* options */ }),
    SolanaProvider({ /* options */ }),
    BitcoinProvider({ /* options */ }),
    SuiProvider({ /* options */ }),
    TronProvider({ /* options */ }),
    StellarProvider({ /* options */ }),
  ],
})
```

### Request a Quote

Now you can interact with the SDK and for example request a quote.

```ts
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](/examples) folder in this repository.

## Documentation

Please checkout the [SDK documentation](https://docs.li.fi/sdk/overview) and our [API reference](https://docs.li.fi/api-reference/introduction) for further information.

## Changelog

The [changelog](/CHANGELOG.md) is regularly updated to reflect what's changed in each new release.
