For a prebuilt React interface, render the Trails Swap component. The widget can manage wallet connections itself or share an app-owned wallet through Trails adapters. For example, you can share an OMS Wallet session through the OMS Wallet connector and the Trails wagmi adapter. This guide instead uses OMS Wallet directly and implements the Trails intent lifecycle without the widget.
Prerequisites
- An active OMS Wallet session from the TypeScript quickstart
- A Trails API key
- A positive balance of the selected source asset and enough balance in an available fee token when the origin transaction is not sponsored
Install the dependencies
Choose a destination asset
The example starts with native POL on Polygon PoS as the source asset. Use the zero address for a native token or the contract address for an ERC-20 token. UsegetTokenList to populate the destination picker, then filter the result to networks supported by OMS Wallet. This example searches for USDC on Polygon PoS to keep the flow focused:
chainIds when your picker supports cross-chain destinations. The token catalog provides destination candidates; quoteIntent confirms whether Trails has a live route for the selected pair and amount.
This guide selects native USDC on Polygon from the catalog. In your application, replace this selection with the token chosen in your asset picker:
Quote the selected route
Request an exact-input quote for the selected amount. A successful quote confirms the live route, and Trails selects the swap and bridge providers automatically:slippageTolerance applies to this quote. Request a new quote when the amount or either asset changes, or when expiresAt passes. Do not commit the intent until the user confirms the current values.
Commit and submit the origin transaction
Commit the quoted intent, then submit the exact deposit transaction returned by that intent through OMS Wallet:txnId and the Trails intentId so your application can recover an uncertain status without submitting the origin transaction again.
Execute and monitor the intent
Give Trails the confirmed origin transaction hash, then wait for the intent to reach a terminal state:intentId instead of submitting the origin transaction again.
For provider overrides and other advanced configuration, see route providers. For details about quoting, committing, executing, and monitoring intents, see the Trails API SDK reference.