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.Authentication
All API requests require an API key passed in theX-Access-Key header.
Get Your API Key: Join the Trails Telegram group or email to request your API access key.
Core Workflow
Every interaction through Trails follows this flow: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: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)
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.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
- 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
Error Handling
The API returns errors in a consistent JSON format:Error Codes
| Code | Name | Description | HTTP Status |
|---|---|---|---|
| 2000 | InvalidArgument | Request parameter is invalid or malformed | 400 |
| 2001 | Unexpected | Unexpected server error | 500 |
| 2002 | Unavailable | Requested resource is unavailable | 400 |
| 2003 | QueryFailed | Database or external query failed | 400 |
| 2004 | IntentStatus | Intent is in an invalid state for this operation | 422 |
| 7000 | IntentsSkipped | Transaction doesn’t require an intent (same chain/token) | 400 |
| 7001 | QuoteExpired | Quote has expired, request a new one | 400 |
| 8000 | NotFound | Resource not found | 400 |
| 8008 | UnsupportedNetwork | Chain ID is not supported | 422 |
| 8009 | ClientOutdated | SDK/client version is outdated | 422 |
| 9000 | IntentsDisabled | Intents service is temporarily unavailable | 400 |
Handling Errors
Quote Expiration
Quotes have strict time limits:| Stage | Time Limit | What Happens |
|---|---|---|
| Quote validity | 5 minutes | Quote expires, request a new one |
| After CommitIntent | 10 minutes | Must call ExecuteIntent within this window |
| Intent execution | N/A | Trails handles execution timing |
Rate Limiting
The API uses rate limiting to ensure service reliability. If you exceed limits, you’ll receive HTTP 429 responses.| Limit Type | Value | Notes |
|---|---|---|
| Requests per second | 50 | Per API key |
| Burst limit | 100 | Short burst allowance |
| QuoteIntent calls | 20/min | Rate-limited separately |
- Cache
GetChains,GetTokenListresponses (they change infrequently) - Batch balance checks where possible
- Implement exponential backoff on 429 responses
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
- GetIntentHistory - Get complete transaction history with receipts 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