> ## Documentation Index
> Fetch the complete documentation index at: https://docs.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 transaction for you. You pass a `vaultId` and a plain amount like `'10.5'` — Dynamic looks up the vault's address and decimal places for you, so you never have to handle those yourself.

Before a wallet's first deposit into a vault, it needs to give the vault contract permission to move its tokens. This is called an **approval** (or **allowance**). If the wallet hasn't approved enough yet, `depositToYieldVault` signs and sends that approval automatically, before the deposit — `onStepChange` tells you which of the two is happening so you can reflect it in your 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 the approval transaction (see above). Only fires when the wallet hasn't already approved enough. |
| `transaction` | Signing the deposit transaction.                                                                         |

<Warning>
  A resolved `depositToYieldVault` call means the deposit transaction was **sent**, not that it finished. See [Waiting for confirmation](#waiting-for-confirmation) before showing a success state to the user.
</Warning>

## Waiting for confirmation

`transactionHash` is returned as soon as the deposit is broadcast to the network — it can still fail or revert after that. Wait for a receipt before telling the user their deposit succeeded:

```typescript theme={"system"}
import { depositToYieldVault, getActiveNetworkData } from '@dynamic-labs-sdk/client';
import { createPublicClientFromNetworkData } from '@dynamic-labs-sdk/evm/viem';

const { transactionHash } = await depositToYieldVault({
  vaultId: 'fb-eth-galaxy-usdc-fw-01',
  walletAccount,
  amount: '10.5',
});

const { networkData } = await getActiveNetworkData({ walletAccount });
const publicClient = createPublicClientFromNetworkData({ networkData });

const receipt = await publicClient.waitForTransactionReceipt({
  hash: transactionHash as `0x${string}`,
});

if (receipt.status !== 'success') {
  throw new Error('Deposit transaction reverted');
}
```

## 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, so the position refetches automatically. That refetch can still briefly show the old balance, since the deposit transaction may not be mined yet — see [Waiting for confirmation](#waiting-for-confirmation).

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