Ship a chain-agnostic aggregator into your dApp (copy-paste friendly)
A minimal, calm walkthrough that shows how to request and execute LiFi routes. All TypeScript, ready to drop into your product.
What you’ll learn
· Configure LiFi with createConfig inside an API Route
· Build RoutesRequest payloads to ask for cross-chain paths
· Read steps, costs, and timing from the response
· Hand the route to a wallet for execution (sample included)
Learning path
1) Initialize the SDK
Call createConfig with your integrator ID and API URL on the server.
2) Request routes
Construct RoutesRequest from chain/token/amount and call the SDK via API Route.
3) Execute
Send the preferred route to executeRoute with your wallet to finish approvals and swaps.
Request routes
Cross chainPick chains, tokens, and amount. We call the LiFi SDK via a Next.js API Route and show the top 3 viable routes. A wallet execution snippet sits below.
Execution snippet (after wallet connect)
Minimal loop that passes the route into executeRoute. Use your wallet stack (wagmi, rainbowkit, etc.) to supply a signer/provider.
import { createConfig, executeRoute } from '@lifi/sdk';
import { walletClientToSigner } from '@wagmi/core/providers'; // choose any wallet lib
async function executePreferredRoute(route) {
const signer = /* grab signer from your wallet */;
await executeRoute(
createConfig({ apiUrl: 'https://li.quest/v1', integrator: 'lifiDemo' }),
{
signer,
route,
updateCallback: (update) => {
console.log(update.process.id, update.process.status);
},
}
);
}
executeRoute handles allowance, bridging, and swapping for you; updateCallback streams progress states.