Live Demo
Try the Trails widget live. Configure, preview, and copy code.
React Starter Kit
Minimal template for Trails with Earn, Swap, Pay, and Fund modes integrated.
NextJS Starter Kit
Minimal NextJS template for Trails with Earn, Swap, Pay, and Fund modes integrated.
Get Your API Key: Join the Trails Telegram group to request your API access key for Trails.
Prerequisites
- React 18+ (18.0 or newer)
1
Install the SDK and dependencies
2
3
Handle Events (Optional)
Listen to various events during the transaction flow:Trails has a wallet connection flow integrated into the widget so users can connect via the widget or utilize another connector such as RainbowKit, Privy, etc.
Using Hooks? If you plan to use Trails hooks (like
useQuote, useTokenBalances, etc.), wrap your app with TrailsProvider. See the Hooks documentation for setup details.Available Modes
The widget supports several modes for different use cases:- Pay - Exact output amount (user pays exactly what’s specified)
- Fund - Deposit/top-up (user chooses amount to send)
- Swap - Cross-chain token swapping
- Earn - Integrated yield farming with various protocols
Script Import
While we recommend using the React component, you can also embed via a script tag in a non-React site. You can load the Trails widget from various CDNs:CDN Recommendations
- unpkg:
https://unpkg.com/0xtrails@latest/dist/umd/trails.min.js - jsDelivr:
https://cdn.jsdelivr.net/npm/0xtrails@latest/dist/umd/trails.min.js - Specific Version: Replace
@latestwith@1.0.0(or your desired version) for production use
For production applications, we recommend pinning to a specific version rather than using
@latest to ensure consistent behavior.