> ## Documentation Index
> Fetch the complete documentation index at: https://anypay-docs-update-resources-2026-06-29.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Earn

> How Trails supports common flows for DeFi protocols, yield opportunities, perpetual exchanges, vault deposits, and more to accelerate TVL and volume.

## Earn with Trails

Trails simplifies DeFi yield deposits by natively integrating with protocols across chains — surfacing APY, TVL, and other metrics, and handling all swapping and bridging to the vault or pool token in a single transaction.

## Use cases

* Deposit into lending protocols like Aave or Morpho
* Fund yield aggregator vaults like Yearn Finance
* Fund auto-compounding yield strategies

## Examples

### Deposit into a user-selected vault

Trails has integrated multiple DeFi pools and vaults across Aave, Morpho, and others. Users can pick from the integrated set out of the box:

<CodeGroup>
  ```tsx EarnWidget.tsx theme={null}
  import { Earn } from '0xtrails/widget'

  export const App = () => {
    return (
      <Earn
        apiKey="YOUR_API_KEY"
        renderInline={true}
        theme="auto"
        onEarnSuccess={({ sessionId }) => {
          console.log('Deposit completed:', sessionId)
        }}
      />
    )
  }
  ```
</CodeGroup>

### Deposit into a specific DeFi pool

For natively supported protocols like Aave and Morpho, use composable actions — no ABI encoding required. The `lend` and `deposit` builders handle the contract calls internally:

```tsx theme={null}
import { useTrailsSendTransaction, lend, erc20Utils } from '0xtrails'

export function AaveLendButton({ recipient }: { recipient: `0x${string}` }) {
  const { sendTransaction, isPending } = useTrailsSendTransaction({
    actions: [
      lend({
        marketId: 'base-usdc-aave-v3-lending',
        amount: '100',
      }),
    ],
  })

  return (
    <button
      disabled={isPending}
      onClick={() =>
        sendTransaction({
          to: recipient,
          tokenAddress: erc20Utils.USDC.addressOn('base'),
          tokenAmount: '100',
        })
      }
    >
      {isPending ? 'Sending...' : 'Supply 100 USDC to Aave'}
    </button>
  )
}
```

Use [`useEarnMarkets`](/sdk/composable-actions/markets-and-providers) to discover available `marketId` values at runtime. For protocols not covered by the action builders, see [Composable Actions — custom](/sdk/composable-actions/building-actions#custom-arbitrary-contract-call-escape-hatch).

## Next steps

* [**Earn mode configuration**](/sdk/modes/earn) — complete configuration options
* [**Composable actions**](/use-cases/composable-actions) — chain `lend`, `deposit`, and `swap` without encoding calldata by hand
* [**SDK configuration**](/sdk/configuration) — widget setup and event handling
* [**Theming**](/sdk/theming) — customize appearance
* [**Tokens and chains**](/sdk/tokens-and-chains) — supported protocols
