> ## Documentation Index
> Fetch the complete documentation index at: https://docs.polygon.technology/llms.txt
> Use this file to discover all available pages before exploring further.

# Earn accounts

> Offer customers a yield-bearing account powered by onchain lending markets, funded from a card or bank in one step.

High-yield savings is one of the most requested features in consumer fintech, and one of the most expensive to build. Traditional options require a banking charter, balance sheet exposure, or a complex treasury operation. Onchain lending markets like Aave and Morpho offer institutional-grade yields on stablecoins, but integrating them typically means building DeFi infrastructure from scratch.

The cross-chain layer handles that. Your customer funds from a card or bank account, and the money lands in a yield-bearing position in one action. You define the destination protocol; the SDK handles the routing, bridging, and deposit.

## What your customers experience

A customer opens your app, taps "Add funds," enters an amount, pays with their debit card, picks a market, and sees their balance earning yield. All of it happens in under two minutes, with no crypto knowledge required. The stablecoin acquisition, cross-chain routing, and vault deposit happen in the background.

When they want to withdraw, the same infrastructure runs in reverse.

## What you build

Drop in the `Earn` component to open a market selector. Customers fund from any source and pick where to deposit; the SDK handles the routing, bridging, and deposit.

```tsx theme={null}
import { Earn } from "0xtrails";

<Earn
  apiKey="YOUR_API_KEY"
  onEarnSuccess={(result) => {
    // Update customer balance in your system
  }}
/>
```

## Product-defined destinations

To target a specific vault or chain a deposit with another action (e.g., swap then deposit), use composable actions. These let you predefine the protocol, the route, and any intermediate steps.

```tsx theme={null}
import { useTrailsSendTransaction, swap, deposit, dynamic } from "0xtrails";

const { sendTransaction } = useTrailsSendTransaction({
  to: {
    chain: "polygon",
    actions: [
      swap({
        tokenIn: "USDC",
        tokenOut: "wstETH",
        amountIn: dynamic(),
      }),
      deposit({
        marketId: "yearn-wsteth-vault",
        token: "wstETH",
        amount: dynamic(),
      }),
    ],
  },
});
```

The customer funds from their card or bank. The SDK converts to wstETH and deposits into the vault in a single atomic batch.

## Supported protocols

| Protocol | Type            | Networks                                    |
| -------- | --------------- | ------------------------------------------- |
| Aave V3  | Lending         | Ethereum, Polygon, Base, Arbitrum, and more |
| Morpho   | Vault / Lending | Ethereum, Base, Polygon                     |
| Yearn    | Vault           | Ethereum, Polygon, Arbitrum                 |

Use `useEarnMarkets` to query available markets by chain, token, and protocol at runtime.

## How a yield product fits together

A yield product has three parts:

1. **Funding**: The SDK accepts card, bank, or crypto and routes to your vault
2. **Position tracking**: Your backend reads the customer's vault balance to display their yield
3. **Withdrawal**: The SDK routes funds from the vault back to the customer's preferred destination

The SDK handles the first part entirely. The second integrates with standard ERC-4626 or protocol-specific balance reads. The third uses the withdraw flow for outbound transfers.

<Note>
  For a complete walkthrough of funding a Morpho vault, see the [Morpho vault deposit guide](/wallets/morpho-vault-deposit).
</Note>
