0xtrails package unless stated otherwise.
TrailsProvider
Apps without wagmi and react-query
The Trails SDK uses wagmi and@tanstack/react-query internally. If your app already sets up those providers, TrailsProvider will use them automatically.
If your app does not already include these providers, you need to add them above TrailsProvider:
This requirement is temporary. A future SDK release will bundle these dependencies so only
TrailsProvider is needed.Configuration Options
Chains
getSupportedChains():Promise<Chain[]>useSupportedChains():{ supportedChains: Chain[], isLoadingChains: boolean }
Utility Functions
Chain Type
Tokens
useTokenList():{ tokens: Token[] | undefined, isLoadingTokens: boolean }useSupportedTokens({ chainId?: number }):{ supportedTokens: Token[], isLoadingTokens: boolean }getSupportedTokens():Promise<Token[]>
Additional Helpers
Token Type
The unifiedToken type is used throughout the Trails SDK:
Balances
useTokenBalances(address, options?): Returns sorted token balances enriched with USD priceuseTokenBalancesForMultipleAccounts(addresses, options?): Returns token balances for multiple accountsuseAccountTotalBalanceUsd(address): Returns total USD balance across tokensuseHasSufficientBalanceUsd(address, targetUsd): Check if account has sufficient USD balanceuseHasSufficientBalanceToken(address, tokenAddress, tokenAmount, chainId): Check token balance
Example Usage
useTokenBalances
Signature:Token[] with balance fields populated. See the Token Type above for all available fields including balance, balanceFormatted, balanceDisplay, balanceUsd, etc.
useTokenBalancesForMultipleAccounts
Fetches token balances for multiple wallet addresses in a single API call. More efficient than callinguseTokenBalances multiple times.
Signature:
Quotes and Swapping
useQuote Hook
TheuseQuote hook provides real-time quotes for token swaps, cross-chain transfers and ability to pass in calldata for executions - enabling you to use Trails headlessly.
from.amount and to.amount are human-readable decimal strings such as "1" or "0.25". Do not pass raw wei strings; the SDK scales amounts using the token decimals.
Pass walletAddress to preview quotes before a wallet is connected. If a connected walletClient.account.address is available, it becomes the quote owner and takes precedence over walletAddress. Executing with send still requires a real wallet client.
Usage Example
Types
useTrailsSendTransaction Hook
useTrailsSendTransaction creates a button-driven transaction flow with the Trails modal. It accepts most useQuote options except from, to, walletClient, and selectedFeeOption; pass destination requirements when calling sendTransaction.
tokenAmount and fromAmount are human-readable decimal strings. Native value remains a raw wei bigint, matching wagmi.
Types
Earn Markets and Providers
useEarnMarkets Hook
Fetch earn markets forlend and deposit actions. Use the returned market id as a marketId.
Types
useEarnProviders Hook
Fetch supported earn providers.Types
useEarnBalances Hook
Fetch earn positions for a wallet. Usechain for one network or chains to batch multiple networks in one backend request.
Types
Constants
TRAILS_ROUTER_PLACEHOLDER_AMOUNT
This constant provides a placeholder value for amounts when encoding calldata in fund mode. It’s used to replace dynamic output amounts during contract execution. Use Case: When creating calldata for fund mode transactions where the final amount isn’t known until execution time, use this placeholder in your encoded function calls. The Trails system will replace it with the actual dynamic amount during contract execution. Example:Transaction History
getAccountTransactionHistory
Gets transaction history for a wallet address interacting with Trails. Signature:useAccountTransactionHistory
Hook for fetching transaction history from a user’s wallet address for a specific chain.Usage
Types
useIntentTransactionHistory
React hook for fetching transaction history for a specific intent address. Usage:getTxTimeDiff
Gets the time difference for a transaction in human-readable format. Signature:(timestamp: string | number) => string
Usage:
SDK Utilities
SDK_VERSION: Current SDK version stringgetVersion(): Returns the current SDK version at runtime
FundMethod Type
FundMethod is exported as a strict union: "wallet" | "direct-transfer" | "onramp-mesh" | "onramp-meld".
Encoders
getERC20TransferData
Encodes ERC20 transfer calldata for token transfers. Signature:(params: { recipient: string, amount: bigint }) => string
Usage:
Error Handling
Error Classes
InsufficientBalanceError
Error thrown when a user has insufficient balance to complete a transaction.UserRejectionError
Error thrown when a user rejects a transaction in their wallet.Error Detection Utilities
All error detection functions have the same signature:(error: unknown) => boolean
getPrettifiedErrorMessage
Converts any error into a user-friendly message string. Signature:(error: unknown) => string
Example: Comprehensive Error Handling
useGetIntent
Hook to fetch intent data from the Trails API.Usage
Types
useIntentRecover
Hook for recovering funds from stuck or failed intent transactions. Trails automatically refunds upon reverting, but this hook handles situations where funds are stuck without an explicit revert. It automatically selects the intent address (origin or destination) with the highest balance for recovery.Usage
Types
useIntentRecoverWithAddress
Recovery hook designed for apps that handle signing externally (e.g., embedded wallets, or custodial solutions). UnlikeuseIntentRecover which requires a walletClient, this hook accepts a plain walletAddress and exposes getDataToSign so you can sign the EIP-712 typed data with any signing method.
Like useIntentRecover, it automatically selects the intent address (origin or destination) with the highest balance for recovery.
Usage
Types
Comparison with useIntentRecover
useCommitIntent / useExecuteIntent
Mutation hooks for committing and executing intents. These are lower-level hooks for advanced users who need direct control over the intent lifecycle.useCommitIntent
useExecuteIntent
TrailsClient
For advanced use cases, you can access the underlying Trails API client directly.useTrailsClient Hook
getTrailsClient Function
For non-React contexts:Advanced: Intent Functions
Types
calculateOriginAndDestinationIntentAddresses
Calculates both origin and destination intent addresses. Signature:commitIntent
Commits an intent to the blockchain. Signature:(params: CommitIntentParams) => Promise<CommitIntentResult>
Usage:
sendOriginTransaction
Sends the origin transaction for an intent. Signature:(params: SendOriginTxParams) => Promise<string>
Usage: