Skip to main content
Use the Trails Earn APIs to discover current markets and prepare deposits and withdrawals, then submit the returned transactions with an active OMS Wallet session. This guide uses a Polygon vault as a concrete example.
For a prebuilt React interface with market selection, deposits, and withdrawals, render the Trails Earn 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 calls the Earn APIs without the widget.

Prerequisites

  • An active OMS Wallet session from the TypeScript quickstart
  • A Trails API key
  • A balance of the selected market’s input asset and enough balance in an available fee token when the transaction is not sponsored
This guide submits mainnet transactions with real funds. Earn markets differ in provider, rate, fees, liquidity, and risk. Present the selected market’s current details before asking the user to confirm a deposit.

Install the Trails packages

Discover an Earn market

Do not hardcode a market ID. Fetch the current catalog and present the available markets for the user to select:
This example lists vaults and uses the selected market’s first supported input asset to keep the flow focused. Use type: 'lending' to list lending markets, or add search: 'USDC' to filter by asset. Refresh the catalog before preparing a deposit because market availability can change. See Earn markets and providers for other filters.

Prepare and submit a deposit

Pass a human-readable amount and the selected market’s input asset to yieldCreateEnterAction. Trails may return more than one unsigned transaction, such as an approval followed by the deposit. Submit every non-message transaction in order:
Each call to sendTransaction has its own OMS transaction lifecycle. Confirm a successful terminal status before submitting the next transaction in the sequence.

Read Earn positions

Earn balance reads do not require the active session and can query any wallet address. Request the wallet’s positions on the selected network and match each yieldId to the current market catalog:
Treat the returned rate and USD value as current display data. Refresh the position after a deposit or withdrawal reaches a successful terminal status.

Withdraw a position

Use a positive balance from the previous response and verify that its current market permits exits. This example withdraws the full displayed position:
Refresh the Earn balances after the final withdrawal transaction succeeds. Preserve each OMS txnId so you can resolve an uncertain transaction status before retrying.

Combine a swap and deposit

To swap into a market’s input asset and deposit it in one same-chain transaction, use Trails composable swap and lend or deposit actions with dynamic(). This action-based flow is separate from the routed intent lifecycle in the swap guide. See building composable actions for the action builders and the Trails actions example for a complete OMS Wallet implementation.