For the complete documentation index, see llms.txt. This page is also available as Markdown.

Integrating the LI.FI SDK

The LI.FI SDK lets you add cross-chain and same-chain swaps and bridging directly inside your Somnia dApp. Instead of redirecting users to an external bridge, you request a route, execute it, and track its status. All from your own interface.

Under the hood, LI.FI aggregates dozens of bridges and DEX aggregators across 50+ chains, normalises token standards, and picks the optimal route. Your dApp only talks to one SDK.

In this guide, you'll learn how to:

  • Install and configure the LI.FI SDK for Somnia

  • Request a quote to bridge assets into Somnia

  • Execute the route and track its status in your app

  • Query supported chains, tokens, and tools to keep your UI accurate

The LI.FI SDK is a JavaScript/TypeScript toolkit that runs in both front-end and back-end environments. This guide shows the front-end (browser wallet) flow. For the full API surface and the latest details, always refer to the official docs: https://docs.li.fi/sdk/overview.

Prerequisites

Before you start, ensure you have:

  • A working JavaScript/TypeScript dApp (React or Next.js recommended). This guide assumes familiarity with both.

  • Wallet connection already set up. If not, see Wallet Integration and Auth.

  • Node.js 18+ and a package manager (npm, pnpm, or yarn).

  • The Somnia network details on hand:

Property
Value

Chain ID

5031

Native currency

SOMI (18 decimals)

RPC URL

https://api.infra.mainnet.somnia.network/

Explorer

https://explorer.somnia.network

Step 1: Install the SDK

The SDK uses Viem under the hood, so install it alongside.

This guide was written and verified against @lifi/sdk v3.16.x and viem v2.x. API surfaces evolve — if a signature differs in your version, the official SDK docs are the source of truth.

Step 2: Configure the SDK

Call createConfig once when your app boots. The integrator string identifies your app to LI.FI (and is used for fee monetisation later).

Because Somnia may not ship in Viem's default chain list, define it explicitly with defineChain so the SDK's wallet provider can switch to it.

Step 3: Request a quote

A quote is a single, ready-to-execute route with the optimal pricing LI.FI could find. The example below bridges USDC on Arbitrum → USDC.e on Somnia (routed via Stargate at the time of writing).

Amounts are always passed as strings in the token's smallest unit (USDC has 6 decimals, so 10 USDC = "10000000"). A chain's native token is represented by the zero address.

Tokens routable to Somnia

These are the tokens LI.FI can currently route to Somnia (Chain ID 5031):

Symbol
Address
Decimals
Notes

SOMI

0x0000000000000000000000000000000000000000

18

Native gas token

WSOMI

0x046EDe9564A72571df6F5e44d0405360c0f4dCab

18

Wrapped SOMI

USDC.e

0x28BEc7E30E6faee657a03e19Bf1128AaD7632A00

6

Bridged USDC (Stargate)

USDT

0x67B302E35Aef5EEE8c32D934F5856869EF428330

6

Bridged USDT (Stargate)

WETH

0x936Ab8C674bcb567CD5dEB85D8A216494704E9D8

18

Wrapped ETH

Step 4: Execute the route

A quote must first be converted to a route with convertQuoteToRoute, then passed to executeRoute. The SDK handles token approvals, network switching, and signing through the wallet provider you configured in Step 2. Use updateRouteHook to react to progress in your UI.

executeRoute also accepts other hooks such as acceptExchangeRateUpdateHook (confirm a changed rate before continuing) and switchChainHook. See the official Execute Routes guide for the full list.

Step 5: Handle the outcome

Status updates arrive through the updateRouteHook from Step 4, read each step's execution.status and execution.process to drive your UI. Cross-chain transfers don't always end in an exact 1:1 result, so handle the final states explicitly:

Final state
Meaning
What to show the user

Completed

Success, exact destination token received

"Funds arrived on Somnia"

Partial

Success, but a different token was received (still full value)

"Completed, received an alternate token"

Refunded

The transfer failed and funds were returned

"Refunded on the source chain"

Failed

Execution failed

Prompt the user to retry or contact support

A same-chain swap is atomic: it either fully succeeds or reverts. A cross-chain transfer can have the bridge succeed while the destination step fails, in that case the bridged asset is refunded on the destination chain.

To resume tracking an interrupted transfer (for example, after a page reload), the SDK can pick up an in-progress route again. See the official Execute Routes guide. For server-side or out-of-band status checks, query the REST status endpoint directly.

Step 6: Keep your UI in sync

Use the SDK's query helpers to populate dropdowns and verify that Somnia routes and tokens are live before showing them to users.

Monetization (optional)

Integrators can charge a fee on transactions routed through their app. Configure a fee when requesting a route and withdraw collected fees via LI.FI's Partner Portal.

See the official guide for the current setup: https://docs.li.fi/sdk/monetize-sdk.

Troubleshooting

  • No route found: Try a different token pair or a larger amount. Very small amounts may not cover bridge/gas costs.

  • Slippage / minimum-received error: Increase the slippage parameter (default 0.005 = 0.5%) when requesting the quote.

  • Rate limited (429): Without an API key you're limited to 200 requests / 2 hours. Request a key for production and back off with retries.

  • Insufficient balance: Ensure the user holds enough of the source token plus native gas on the source chain.

  • Network switch fails: Confirm Somnia (5031) is added to the user's wallet. See Connect Your Wallet to Mainnet.

Need Help?

Disclaimers

  • LI.FI is a third-party provider. Always integrate from the official packages (@lifi/sdk) and verify chain/token data against the live API.

  • Bridging and swapping involve smart-contract and market risk. Test thoroughly on a small amount before enabling production flows.

Last updated