Skip to main content
Portal’s React Native SDK provides comprehensive cross-chain bridging and swapping capabilities through the portal.trading.lifi API. This guide covers getting quotes, finding routes, executing swaps and bridges, and tracking transaction status.

Overview

The Li.Fi functionality allows you to:
  • Get quotes for bridging or swapping tokens across chains
  • Find routes to discover the best paths for your cross-chain transfers
  • Execute swaps and bridges by signing and submitting transactions
  • Track transaction status for cross-chain transfers

Prerequisites

Before using Li.Fi operations, ensure you have:
  • A properly initialized Portal client
  • An active wallet with the required token(s) on the source network (see Create a wallet)
  • Li.Fi integration enabled in your Portal Dashboard (see Li.Fi Integration)

Getting a Quote

import { LifiQuoteRequest } from '@portal-hq/trading'

async function getQuote(portal: Portal) {
  const fromAddress = await portal.getAddress('eip155:1')

const request: LifiQuoteRequest = {
  fromChain: 'eip155:8453',
  toChain: 'eip155:42161',
  // Amount in wei (1 ETH = 1e18 wei)
  // 1_000_000_000_000 wei = 0.000001 ETH
  fromAmount: '1000000000000',
  fromToken: 'ETH',
  toToken: 'USDC',
  fromAddress,
}


  const response = await portal.trading.lifi.getQuote(request)
  const quote = response.data?.rawResponse

  if (!quote) return

  console.log('To amount:', quote.estimate?.toAmount)

  if (quote.transactionRequest) {
    await executeTransaction(
      portal,
      quote.transactionRequest,
      request.fromChain
    )
  }
}

Finding Routes

import { LifiRoutesRequest } from '@portal-hq/trading'

async function getRoutes(portal: Portal) {
  const fromAddress = await portal.getAddress('eip155:1')

const request: LifiRoutesRequest = {
  fromChainId: 'eip155:8453',
  toChainId: 'eip155:42161',
  fromTokenAddress: 'ETH',
  toTokenAddress: 'USDC',

  // Amount in wei (1 ETH = 1e18 wei)
  // 1_000_000_000_000 wei = 0.000001 ETH
  fromAmount: '1000000000000',

  fromAddress,
}

  const response = await portal.trading.lifi.getRoutes(request)
  const routes = response.data?.rawResponse?.routes ?? []

  const route =
    routes.find(r => r.tags?.includes('RECOMMENDED')) ?? routes[0]

  if (!route) return

  await processRouteSteps(portal, route.steps, request.fromChainId)
}

Getting Route Step Details

import { LifiStep, LifiStepTransactionRequest } from '@portal-hq/trading'

async function getRouteStep(
  portal: Portal,
  step: LifiStep
): Promise<LifiStep | null> {
  const response = await portal.trading.lifi.getRouteStep(
    step as LifiStepTransactionRequest
  )

  return response.data?.rawResponse ?? null
}

Executing Transactions

import { ETHTransactionParam } from '@portal-hq/provider'
import { LifiTransactionRequest } from '@portal-hq/trading'

async function executeTransaction(
  portal: Portal,
  transactionRequest: LifiTransactionRequest,
  chainId: string
) {
  const ethTx: ETHTransactionParam = {
    from: transactionRequest.from,
    to: transactionRequest.to,
    value: transactionRequest.value ?? '0x0',
    data: transactionRequest.data,
  }

  const response = await portal.request(
    chainId,
    'eth_sendTransaction',
    [ethTx]
  )

  console.log('Tx hash:', response.result)
}

Note
LifiTransactionRequest may include gasLimit and gasPrice. You can omit these fields to let Portal estimate gas automatically, or include them if you prefer to use Li.Fi’s suggested values.

Processing Multi-Step Routes

async function processRouteSteps(
  portal: Portal,
  steps: LifiStep[],
  chainId: string
) {
  for (const step of steps) {
    const stepWithTx = await getRouteStep(portal, step)
    if (!stepWithTx?.transactionRequest) {
      throw new Error('Missing transactionRequest')
    }

    await executeTransaction(
      portal,
      stepWithTx.transactionRequest,
      chainId
    )
  }
}

Tracking Transaction Status

import { LifiStatusRequest } from '@portal-hq/trading'

async function getStatus(
  portal: Portal,
  txHash: string,
  fromChain: string
) {
  const request: LifiStatusRequest = {
    txHash,
    fromChain,
  }

  const response = await portal.trading.lifi.getStatus(request)
  const status = response.data?.rawResponse

  console.log('Status:', status?.status)
}

Polling Until Completion

async function pollUntilDone(
  portal: Portal,
  txHash: string,
  fromChain: string
) {
  while (true) {
    const response = await portal.trading.lifi.getStatus({
      txHash,
      fromChain,
    })

    const status = response.data?.rawResponse?.status
    if (status === 'DONE') return true
    if (status === 'FAILED') return false

    await new Promise(r => setTimeout(r, 2000))
  }
}

Supported Networks

Li.Fi supports a wide range of networks for bridging and swapping. Common networks include:
  • Monad (eip155:143)
  • Ethereum (eip155:1)
  • Polygon (eip155:137)
  • Base (eip155:8453)
  • Arbitrum (eip155:42161)
  • Optimism (eip155:10)
  • Avalanche (eip155:43114)
  • And many more…
For the complete list of supported networks, refer to the Li.Fi documentation.

Next Steps