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
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: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 toyieldCreateEnterAction. Trails may return more than one unsigned transaction, such as an approval followed by the deposit. Submit every non-message transaction in order:
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 eachyieldId to the current market catalog:
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: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 composableswap 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.