> For the complete documentation index, see [llms.txt](https://docs.yo.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.yo.xyz/integrations/integration-guides/sdk/react/hooks/use-deposit.md).

# use deposit

Mutation hook for depositing assets into a vault via the gateway contract, with transaction tracking and automatic query invalidation.

```tsx
const { deposit, isPending, isSuccess, hash } = useDeposit({ vault: 'yoETH' })
```

## Usage

```tsx
import { useDeposit } from '@yo-protocol/react'
import { parseEther } from 'viem'

function DepositButton() {
  const {
    deposit,
    isPending,
    isSuccess,
    hash,
    error,
    reset,
  } = useDeposit({
    vault: 'yoETH',
    slippageBps: 50,
    onSubmitted: (hash) => console.log('Deposited:', hash),
    onError: (err) => console.error(err),
  })

  return (
    <div>
      <button onClick={() => deposit(parseEther('0.1'))} disabled={isPending}>
        {isPending ? 'Depositing...' : 'Deposit 0.1 ETH'}
      </button>

      {isSuccess && <p>Confirmed! Tx: {hash}</p>}
      {error && (
        <p>
          Error: {error.message}
          <button onClick={reset}>Dismiss</button>
        </p>
      )}
    </div>
  )
}
```

## Options

| Option        | Type                     | Default     | Description                                        |
| ------------- | ------------------------ | ----------- | -------------------------------------------------- |
| `vault`       | `Address \| VaultId`     | —           | **Required.** Target vault                         |
| `slippageBps` | `number`                 | `50` (0.5%) | Slippage tolerance in basis points                 |
| `onSubmitted` | `(hash: Hash) => void`   | —           | Called after the transaction is sent               |
| `onConfirmed` | `(hash: Hash) => void`   | —           | Called after the transaction is confirmed on-chain |
| `onError`     | `(error: Error) => void` | —           | Called on error                                    |

## Return Value

| Field       | Type                                | Description                                             |
| ----------- | ----------------------------------- | ------------------------------------------------------- |
| `deposit`   | `(amount: bigint) => Promise<Hash>` | Execute a deposit for the given asset amount            |
| `isPending` | `boolean`                           | `true` while the transaction is being sent or confirmed |
| `isError`   | `boolean`                           | `true` if the transaction failed                        |
| `error`     | `Error \| null`                     | Error object                                            |
| `isSuccess` | `boolean`                           | `true` after the transaction is confirmed on-chain      |
| `hash`      | `Hash \| undefined`                 | Transaction hash once submitted                         |
| `reset`     | `() => void`                        | Reset all state back to idle                            |

## Behavior

| Behavior                  | Detail                                                                                                        |
| ------------------------- | ------------------------------------------------------------------------------------------------------------- |
| **Query invalidation**    | Automatically invalidates `useVault` and `useUserBalance` queries on success                                  |
| **Confirmation tracking** | Uses `useWaitForTransactionReceipt` internally — `isSuccess` flips to `true` only after on-chain confirmation |
| **Error propagation**     | Fires both the local `onError` callback and the global `YieldProvider.onError` handler                        |
| **Slippage**              | The gateway calculates the minimum output based on `slippageBps` and reverts if not met                       |

{% hint style="warning" %}
**Approval required**

The user must have approved the gateway to spend their tokens before depositing. Use `useApprove` to handle this — see the [useApprove docs](broken://pages/4603efa0d6ec049f211a87ef47ad36e5fb912db9).
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.yo.xyz/integrations/integration-guides/sdk/react/hooks/use-deposit.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
