> ## 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.

# Deposit into yield markets

> Let customers fund a yield position from a card, exchange, or any wallet in one action, then show their positions in your app.

This guide shows you how to let a customer open a yield position in one step: they fund from whatever they hold, and the deposit into the lending market or vault happens as part of the same intent. You need an OMS publishable key (`pk_...`) and the [SDK installed](https://docs.polygon.technology/cross-chain/sdk/index.md).

## Let the customer pick a market

Render `Earn` with no destination to show the market selector. The customer chooses a market, a funding source, and an amount.

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

<Earn
  apiKey="pk_..."
  onEarnSuccess={({ intentId }) => recordDeposit(intentId)}
/>
```

Markets include Aave lending pools and Morpho vaults across supported chains. The widget includes a withdrawal tab for existing positions.

## Deposit into a market you choose

Most products offer a fixed set of markets. Encode the market's deposit call and pass it as `to.calldata`, with `TRAILS_HYDRATE_PLACEHOLDER_AMOUNT` where the amount goes. At execution, the placeholder is replaced with the amount that actually arrived, so the deposit uses every token that landed after fees.

```tsx theme={null}
import { Earn } from "0xtrails/widget";
import { TRAILS_HYDRATE_PLACEHOLDER_AMOUNT } from "0xtrails";
import { encodeFunctionData, erc4626Abi } from "viem";

const calldata = encodeFunctionData({
  abi: erc4626Abi,
  functionName: "deposit",
  args: [TRAILS_HYDRATE_PLACEHOLDER_AMOUNT, customerAddress],
});

<Earn
  apiKey="pk_..."
  to={{
    recipient: "0xVAULT_ADDRESS",
    token: "USDC",
    chain: "polygon",
    calldata,
  }}
  onEarnSuccess={({ intentId }) => recordDeposit(intentId)}
/>
```

Set the vault's share recipient to the customer's address, as above, so the position belongs to them. To fund a vault from a card, pass `paymentMethod="CREDIT_DEBIT_CARD"`. For more on encoding destination calls, see [contract calls on arrival](https://docs.polygon.technology/cross-chain/money-actions.md).

## Find markets

`useEarnMarkets` lists markets you can offer, filtered by chain, provider, and type, and sorted by rate. It requires `TrailsProvider`; see [React hooks](https://docs.polygon.technology/cross-chain/sdk/hooks.md).

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

const { data: markets, isLoading } = useEarnMarkets({
  chain: "polygon",
  type: "vault",
  sortBy: "rewardRateDesc",
});
```

## Show a customer's positions

`useEarnBalances` returns a wallet's positions on one or more chains. It reads public state and does not need a connected wallet.

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

const { data: positions } = useEarnBalances({
  walletAddress: customerAddress,
  chains: ["polygon", "base"],
});
```

## From your server

To deposit without the widget, quote an intent with `destinationCallData` set to the encoded deposit. See [quotes and execution](https://docs.polygon.technology/cross-chain/api-reference/quotes.md).
