Skip to content

Quickstart example projects for our developer products (Widget, SDK, API)

Notifications You must be signed in to change notification settings

lifinance/examples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

LI.FI Integration Examples

This repository contains working examples demonstrating how to integrate LI.FI's cross-chain bridging and swapping capabilities into your applications.

📚 Available Examples

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 dev

See the API Example README for detailed documentation.

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 dev

See the SDK Example README for detailed documentation.

🚀 Quick Start

  1. 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
  2. Navigate to the example directory:

    cd api-example  # or cd sdk-example
  3. Install dependencies:

    npm install
  4. Set up environment variables:

    cp env.example .env
    # Edit .env with your wallet credentials
  5. Run the example:

    npm run dev

📋 Prerequisites

  • 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)

🔑 Getting an API Key (Optional)

While the API works without authentication, you can get an API key for higher rate limits:

  1. Visit LI.FI Portal
  2. Create an account and generate an API key
  3. Add it to your .env file as LIFI_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.

📖 Documentation

For comprehensive documentation, visit:

🛠️ What Each Example Includes

API Example Features

  • ✅ Read-only quote fetching
  • ✅ Chain and token discovery
  • ✅ Status checking utilities
  • ✅ Complete transaction execution flow
  • ✅ Error handling with retry logic
  • ✅ Rate limit management

SDK Example Features

  • ✅ 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

🔒 Security Best Practices

  • ⚠️ Never commit your .env file - 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 .env files
  • ⚠️ API keys are optional - Only needed for higher rate limits

🐛 Troubleshooting

Common Issues

"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

📝 Example Workflows

API Example Workflow

  1. Fetch supported chains
  2. Get tokens for specific chains
  3. Request a quote for cross-chain transfer
  4. (Optional) Execute transaction using /advanced/routes
  5. Check transaction status

SDK Example Workflow

  1. Initialize SDK configuration
  2. Check token balance
  3. Request a quote
  4. Convert quote to route
  5. Execute route with progress tracking
  6. Monitor status until completion

🤝 Contributing

These examples are maintained by LI.FI. If you find issues or have suggestions:

📄 License

MIT License - See individual example directories for license details.

🔗 Useful Links


Ready to get started? Choose an example above and follow its README for detailed instructions!

About

Quickstart example projects for our developer products (Widget, SDK, API)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published