This repository contains working examples demonstrating how to integrate LI.FI's cross-chain bridging and swapping capabilities into your applications.
1. API Example
A complete example demonstrating how to use the LI.FI REST API for cross-chain token transfers.
What it covers:
- How to set up an API client with authentication
- Fetching supported chains and tokens
- Requesting quotes for cross-chain transfers
- Checking transaction status
- Error handling and retry logic
- Executing real transactions using the API
Best for:
- Backend integrations
- Server-side applications
- Custom UI implementations
- Applications that prefer REST API over SDK
Get started:
cd api-example
npm install
cp env.example .env
# Edit .env with your credentials
npm run devSee the API Example README for detailed documentation.
2. SDK Example
A complete example demonstrating how to use the LI.FI SDK for cross-chain bridging and swapping.
What it covers:
- How to configure the SDK with EVM providers
- Requesting quotes and routes
- Executing transactions with progress tracking
- Handling exchange rate updates
- Status polling and monitoring
- Balance checking before execution
Best for:
- Frontend applications
- Full-stack applications
- Applications that want SDK convenience features
- Real-time transaction monitoring
Get started:
cd sdk-example
npm install
cp env.example .env
# Edit .env with your credentials
npm run devSee the SDK Example README for detailed documentation.
-
Choose your integration method:
- Use the API Example if you prefer REST API calls and want full control
- Use the SDK Example if you want a higher-level SDK with built-in features
-
Navigate to the example directory:
cd api-example # or cd sdk-example
-
Install dependencies:
npm install
-
Set up environment variables:
cp env.example .env # Edit .env with your wallet credentials -
Run the example:
npm run dev
- Node.js 18 or higher
- A wallet with test funds (for executing transactions)
- Basic understanding of TypeScript/JavaScript
- Familiarity with blockchain concepts (helpful but not required)
While the API works without authentication, you can get an API key for higher rate limits:
- Visit LI.FI Portal
- Create an account and generate an API key
- Add it to your
.envfile asLIFI_API_KEY
Rate Limits:
- Without API key: 200 requests per 2 hours
- With API key: 200 requests per minute and can be increased further on your request.
For comprehensive documentation, visit:
- API Documentation - Complete API reference
- SDK Documentation - SDK quickstart and guides
- LI.FI Docs - Full documentation hub
- ✅ Read-only quote fetching
- ✅ Chain and token discovery
- ✅ Status checking utilities
- ✅ Complete transaction execution flow
- ✅ Error handling with retry logic
- ✅ Rate limit management
- ✅ SDK configuration and setup
- ✅ Quote and route requests
- ✅ Transaction execution with hooks
- ✅ Progress tracking and monitoring
- ✅ Exchange rate update handling
- ✅ Balance checking utilities
- ✅ Status polling
⚠️ Never commit your.envfile - It contains sensitive private keys⚠️ Use test wallets - Only use wallets with minimal funds for testing⚠️ Never expose private keys - Keep them secure and out of version control⚠️ Use environment variables - Store sensitive data in.envfiles⚠️ API keys are optional - Only needed for higher rate limits
"Insufficient balance" error:
- Make sure your wallet has enough tokens for the transfer
- Ensure you have native tokens (ETH, etc.) for gas fees
"No route found" error:
- The requested token pair might not be supported
- Try a different amount or token pair
- Check that both chains are supported
Rate limit errors:
- Get an API key for higher rate limits
- Implement proper retry logic with backoff
- Cache results when possible
Transaction failures:
- Check your wallet has sufficient gas
- Verify the transaction parameters
- Review the error message for specific issues
- Fetch supported chains
- Get tokens for specific chains
- Request a quote for cross-chain transfer
- (Optional) Execute transaction using
/advanced/routes - Check transaction status
- Initialize SDK configuration
- Check token balance
- Request a quote
- Convert quote to route
- Execute route with progress tracking
- Monitor status until completion
These examples are maintained by LI.FI. If you find issues or have suggestions:
- Open an issue on the repository
- Check the LI.FI Documentation for updates
- Visit LI.FI Discord for community support
MIT License - See individual example directories for license details.
- LI.FI Website - Learn more about LI.FI
- LI.FI Portal - Get API keys and manage integrations
- LI.FI Docs - Complete documentation
- LI.FI Discord - Community support
- LI.FI GitHub - Official repositories
Ready to get started? Choose an example above and follow its README for detailed instructions!