Skip to main content
Skip to main content

LI.FI

The LI.FI integration gives web3agent access to cross-chain bridging and swapping across more than 20 EVM-compatible chains. LI.FI aggregates multiple bridge protocols and DEXs, then routes each transfer through the optimal path based on speed, cost, and output amount.

All LI.FI tools use the lifi_ prefix. No configuration is required to start using them. Setting LIFI_API_KEY unlocks higher rate limits for production workloads.

Supported Chains

LI.FI supports all chains that web3agent natively handles, plus many more:

Ethereum, Base, Arbitrum, Optimism, Polygon, Linea, BSC, Avalanche, zkSync Era, Scroll, Mode, Blast, Mantle, Celo, Gnosis, and additional chains including Fantom, Moonbeam, Moonriver, Cronos, Fuse, and others.

Tools

ToolDescription
lifi_get_quoteGet a bridge/swap quote with route details, fees, and estimated time
lifi_execute_bridgeExecute a bridge or cross-chain swap with the active wallet
lifi_prepare_bridge_intentPrepare bridge intent data for external signing (browser wallet flow)

SDK Functions

import { prepareBridgeIntent, executeBridge } from "web3agent";

prepareBridgeIntent

Returns EIP-712 typed data and approval steps for signing in a browser wallet. Used when the signing key lives in the user's wallet rather than on the server.

import { prepareBridgeIntent } from "web3agent";

const intent = await prepareBridgeIntent({
  fromToken: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // USDC on Base
  toToken: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",  // USDC on Arbitrum
  fromAmount: "500000000", // 500 USDC (6 decimals)
  fromChainId: 8453,       // Base
  toChainId: 42161,        // Arbitrum
  fromAddress: "0xYourWalletAddress",
  toAddress: "0xYourWalletAddress",
});

// intent.typedData  — EIP-712 data to sign
// intent.approvals  — token approvals needed before signing
// intent.route      — selected bridge route details

executeBridge

Executes a bridge directly using the server-side wallet. Handles approval transactions, bridge submission, and status tracking.

import { executeBridge } from "web3agent";

const result = await executeBridge({
  fromToken: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
  toToken: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
  fromAmount: "500000000",
  fromChainId: 8453,
  toChainId: 42161,
  toAddress: "0xDestinationAddress",
});

// result.txHash     — source chain transaction hash
// result.bridgeId   — LI.FI bridge tracking ID
// result.status     — "pending" | "done" | "failed"

Bridge Flow

Server-Side Execution (MCP Tool)

When an AI agent calls lifi_execute_bridge, the flow is:

1. lifi_get_quote → fetch optimal route
2. Check token approvals → submit approval tx if needed
3. Submit bridge transaction → source chain tx confirmed
4. Monitor bridge status → destination chain receipt
5. Return final status and destination tx hash

If CONFIRM_WRITES=true (the default), the bridge transaction is queued for confirmation before execution. The AI agent receives a confirmation ID and must call transaction_confirm to proceed.

Browser Wallet Flow (Intent Pattern)

For applications where users sign in their own wallet:

1. prepareBridgeIntent() → returns typed data + approvals
2. User approves tokens in browser wallet (if needed)
3. User signs the bridge intent
4. Submit signed payload to LI.FI relay
5. Monitor status until destination chain confirms

Getting a Quote

Before executing, fetch a quote to see route details:

// Via MCP tool (AI agent)
lifi_get_quote({
  fromToken: "USDC",
  toToken: "USDC",
  fromAmount: "500",
  fromChainId: 8453,
  toChainId: 42161,
})

// Returns:
// {
//   route: { steps: [...], estimatedDuration: 180 },
//   toAmount: "499850000",
//   gasCostUsd: "0.42",
//   feeCostUsd: "0.15",
//   bridgeProtocol: "Across"
// }

LI.FI selects the route automatically. The quote shows which bridge protocol it chose, the estimated output after fees, and the expected time to completion.

Configuration

Optional API Key

Without an API key, LI.FI applies public rate limits. For production use, set:

LIFI_API_KEY=your_key_here npx web3agent

Or in your environment file:

LIFI_API_KEY=your_key_here

Get a key at li.fi.

Write Confirmation

Bridge transactions are write operations. By default, CONFIRM_WRITES=true means the AI agent must confirm before the transaction executes. To allow autonomous execution:

CONFIRM_WRITES=false npx web3agent

Cross-Chain Token Addresses

Token addresses differ across chains. When calling SDK functions directly, use the correct address for each chain. When using MCP tools, the AI agent can resolve symbols automatically via the token resolver.

Common USDC addresses:

ChainChain IDUSDC Address
Ethereum10xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48
Base84530x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913
Arbitrum421610xaf88d065e77c8cC2239327C5EDb3A432268e5831
Optimism100x0b2C639c533813f4Aa9D7837CAf62653d097Ff85
Polygon1370x3c499c542cEF5E3811e1192ce70d8cC03d5c3359

Status Reference

LI.FI bridge transactions go through multiple stages:

StatusMeaning
pendingSource chain transaction submitted
bridgingFunds locked on source chain, bridge processing
doneDestination chain transaction confirmed
failedBridge failed (funds typically returned to sender)
refundedBridge failed and funds returned

Bridge times vary by protocol and chain congestion. Across typically settles in 1-3 minutes. Slower bridges may take 15-30 minutes.