Welcome to the Trails API
The Trails API enables seamless cross-chain token swaps, deposits, payments, and smart contract executions in a simplified interface with the Trails protocol. This guide walks you through the complete flow from requesting a quote to executing a transaction.Get Your API Key: Join the Trails Telegram group to request your API access key.
Core Workflow
Every interaction through Trails follows this flow:1
Get Wallet Balance
Before requesting a quote, fetch the user’s token balances using a multichain Indexer to display total available tokens and amounts for the user to select:2
Get a Quote
Request a quote to see rates, fees, and routing options for your transaction.- ownerAddress: User’s wallet address
- originChainId & destinationChainId: Source and destination chains
- originTokenAddress & destinationTokenAddress: Token contracts
- originTokenAmount: Amount to swap (in token’s smallest unit)
- tradeType:
EXACT_INPUT(specify input) orEXACT_OUTPUT(specify output)
3
Commit the Intent
Lock in the quote by committing the intent with the fetched contract addresses. This reserves the rates.intent object contains everything needed to relay and execute the intent.4
Execute the Transaction
Execute the intent using one of two mutually exclusive methods - either a normal transfer to the intent address or a permit operation if a user wants to pay in a non-native gas token:- Transfer Flow
- Alternative Fee Token Flow
Send tokens to the intent deposit address, then call
ExecuteIntent with the transaction hash:Setup: Instantiate viem
Setup: Instantiate viem
5
- x402 Payments
- AI Agents
- Server-side currency conversion & settlement
- Fund, Swap, Earn, or Pay for any application
- Pass in optional calldata to call any smart contract function
Next Steps
Explore additional endpoints to enhance your integration:Transaction Management
- GetIntent - Retrieve full intent details including quote, fees, and status
- GetIntentReceipt - Poll for transaction status and get receipt with transaction hashes
- WaitIntentReceipt - Stream intent updates with automatic polling until completion
- GetIntentTransactionHistory - Get complete transaction history for a user’s wallet address
Discovery & Search
- SearchIntents - Search and filter intents by status, user, chain, or date range
- GetTokenPrices - Get current USD prices for tokens to display values in your UI
- GetChains - Get list of supported chains
- GetTokenList - Get available tokens for specified chains
- GetExactInputRoutes - Find destination tokens from a source token
- GetExactOutputRoutes - Find source tokens that route to a destination
Support
Need help? Join our community:- Telegram: https://t.me/build_with_trails
- Documentation: Browse the endpoint references for detailed information and advanced use cases
- Demo: Try the interactive playground