Skip to main content

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 the X-Access-Key header.
Get an API key: Sign up and create an API key on the Trails Dashboard

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.
Key Parameters:
  • 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) or EXACT_OUTPUT (specify output)
Use EXACT_INPUT when you know how much you want to spend, and EXACT_OUTPUT when you know exactly how much you need to receive.
3

Commit the Intent

Lock in the quote by committing the intent with the fetched contract addresses. This reserves the rates.
You cannot change the contents of the intent, or the server will reject the commit. The intent object contains everything needed to relay and execute the intent.
Quotes expire 5 minutes after being issued. Once committed, you have 10 minutes to call ExecuteIntent. If either window expires, you’ll need to request a new quote.
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:
Send tokens to the intent deposit address, then call ExecuteIntent with the transaction hash:
5

Monitor Completion

Wait for the transaction to complete using the streaming endpoint:
Now you have an end to end API integration with Trails for seamless chain abstraction flows! You can continue this initial integration for specific use cases such as:
  • 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

Handling Errors

Quote Expiration

Quotes have strict time limits:
Always check quote expiration before committing. The intent.expiresAt timestamp indicates when the quote becomes invalid.

Rate Limiting

The API uses rate limiting to ensure service reliability. If you exceed limits, you’ll receive HTTP 429 responses. Best practices:
  • Cache GetChains, GetTokenList responses (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

Earn

Support

Need help? Join our community: