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

# depositToYieldVault

# depositToYieldVault

Deposits assets into an [Earn](/docs/overview/yield) vault, then signs and sends the resulting transaction. Unlike a swap, this is a single call — Dynamic resolves the vault's contract address and the underlying asset's decimals server-side, so you pass a `vaultId` and a human-readable `amount` rather than fetching a quote and executing it yourself.

When the wallet's current allowance for the vault is short of `amount`, an ERC-20 approval is signed and sent first. `onStepChange` reports which step is in flight so you can reflect it in the UI.

## Usage

```javascript theme={"system"}
import { depositToYieldVault } from '@dynamic-labs-sdk/client';

const { transactionHash } = await depositToYieldVault({
  vaultId: 'fb-eth-galaxy-usdc-fw-01',
  walletAccount,
  amount: '10.5', // 10.5 USDC — human-readable units, not raw
  onStepChange: (step) => {
    console.log('Step:', step); // 'approval' or 'transaction'
  },
});

console.log('Transaction hash:', transactionHash);
```

## Parameters

| Parameter         | Type                                                     | Description                                                                                                                                                                                  |
| ----------------- | -------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `vaultId`         | `string`                                                 | Opaque vault identifier, from [`listYieldVaults`](/docs/javascript/reference/client/list-yield-vaults).                                                                                           |
| `walletAccount`   | `WalletAccount`                                          | The wallet account depositing the assets. Must be an EVM wallet account.                                                                                                                     |
| `amount`          | `string`                                                 | How much of the vault's underlying asset to deposit, in the asset's human-readable units (`'10.5'` USDC, not `'10500000'`). Rejected when it carries more precision than the asset supports. |
| `receiverAddress` | `string` (optional)                                      | The address credited with the vault shares. Defaults to `walletAccount`'s own address.                                                                                                       |
| `onStepChange`    | `(step: 'approval' \| 'transaction') => void` (optional) | Callback invoked when the execution step changes. `'approval'` only fires when the wallet's current allowance is short of `amount`.                                                          |
| `client`          | `DynamicClient` (optional)                               | The Dynamic client instance. Only required when using multiple Dynamic clients.                                                                                                              |

## Returns

`Promise<{ transactionHash: string }>` - The hash of the deposit transaction.

## Step Lifecycle

| Step          | Description                                                                                                 |
| ------------- | ----------------------------------------------------------------------------------------------------------- |
| `approval`    | Signing an ERC-20 approval transaction. Only fires when the current allowance is insufficient for `amount`. |
| `transaction` | Signing the deposit transaction.                                                                            |

## Examples

### With progress UI

```javascript theme={"system"}
import { useState } from 'react';
import { depositToYieldVault } from '@dynamic-labs-sdk/client';

const DepositButton = ({ vaultId, walletAccount, amount, onComplete }) => {
  const [step, setStep] = useState(null);

  const handleDeposit = async () => {
    const { transactionHash } = await depositToYieldVault({
      vaultId,
      walletAccount,
      amount,
      onStepChange: setStep,
    });

    onComplete(transactionHash);
  };

  return (
    <button onClick={handleDeposit} disabled={!!step}>
      {step === 'approval' && 'Approving...'}
      {step === 'transaction' && 'Depositing...'}
      {!step && 'Deposit'}
    </button>
  );
};
```

<Note>
  This example uses React; the JavaScript SDK is framework-agnostic and can be used with any frontend or in Node.
</Note>

## Supported Chains

`depositToYieldVault` only supports EVM wallet accounts — vault actions are EVM-only today. Calling it with a non-EVM `walletAccount` throws a `WalletProviderMethodUnavailableError`, since only EVM wallet providers implement the underlying `executeYieldTransaction` method.

## React

```tsx theme={"system"}
import { useDepositToYieldVault } from '@dynamic-labs-sdk/react-hooks';
import { useState } from 'react';

function DepositButton({ vaultId, walletAccount, amount, onComplete }) {
  const { mutate: deposit, isPending } = useDepositToYieldVault();
  const [step, setStep] = useState(null);

  return (
    <button
      onClick={() =>
        deposit(
          { vaultId, walletAccount, amount, onStepChange: setStep },
          { onSuccess: ({ transactionHash }) => onComplete(transactionHash) },
        )
      }
      disabled={isPending}
    >
      {step === 'approval' && 'Approving...'}
      {step === 'transaction' && 'Depositing...'}
      {!step && 'Deposit'}
    </button>
  );
}
```

`useDepositToYieldVault` invalidates [`useGetYieldPosition`](/docs/javascript/reference/client/get-yield-position) on success — treat that refetch as a nudge, since the deposit is only broadcast (not necessarily mined) when the mutation resolves.

## Related

* [`withdrawFromYieldVault`](/docs/javascript/reference/client/withdraw-from-yield-vault) - Withdraw from a vault
* [`getYieldPosition`](/docs/javascript/reference/client/get-yield-position) - Read the resulting position
* [`listYieldVaults`](/docs/javascript/reference/client/list-yield-vaults) - Find a vault to deposit into
