Overview
This guide will walk you through executing a complete cross-chain bridge transaction using LiFi Contract Types with the Across Protocol integration.Prerequisites
Before starting, ensure you have:- Node.js 16+ installed
- A basic understanding of ethers.js
- Access to an Ethereum RPC provider (Infura, Alchemy, etc.)
- A wallet with some ETH for gas fees
Installation
First, install the required packages:Complete Example
Here’s a complete working example that bridges USDC from Ethereum to Polygon using Across Protocol:Step-by-Step Breakdown
Let’s break down the key parts:Connect to the Contract
Use the factory to create a type-safe contract instance:This gives you a fully typed contract with autocomplete for all methods.
Prepare Bridge Data
Create the
BridgeDataStruct with all required parameters:The
transactionId should be unique for each transaction. Use it to track your bridges.Listening to Events
Monitor your bridge transaction with type-safe event listeners:Bridging with Source Swaps
You can swap tokens before bridging using theLibSwap.SwapDataStruct:
Common Bridge Integrations
Here are the factory imports for other popular bridges:Error Handling
Always wrap your calls in try-catch blocks:Testing
For testing, use a local fork or testnet:Next Steps
Core Concepts
Learn about BridgeData, SwapData, and other key types
API Reference
Explore all available contracts and methods
Examples
Browse more examples for different use cases
LiFi SDK
Use the higher-level LiFi SDK for easier integration