> For the complete documentation index, see [llms.txt](https://docs.zama.org/protocol/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.zama.org/protocol/sdk/api-references/react/usedispatch.md). Agents can also search and read this documentation through its [MCP server](https://docs.zama.org/protocol/~gitbook/mcp).

# useDispatch

Mutation hook that dispatches a vault batcher's open batch.

Mutation hook that dispatches a batcher's open batch with the SDK's signer. Wraps [`VaultClient.dispatch`](https://docs.zama.org/protocol/sdk/api-references/sdk/vaultclient.md#dispatch).

It dispatches whatever batch is open on the batcher. Any account may send it.

## Import

```ts
import { useDispatch } from "@zama-fhe/react-sdk/vaults";
```

## Usage

{% tabs %}
{% tab title="DispatchButton.tsx" %}

```tsx
import { useBatch, useDispatch } from "@zama-fhe/react-sdk/vaults";
import type { BatchRef } from "@zama-fhe/sdk/vaults";

function DispatchButton({ batchRef }: { batchRef: BatchRef }) {
  const { data: batch } = useBatch(batchRef);
  const dispatch = useDispatch();

  if (!batch?.actions.includes("dispatch")) return null;

  return (
    <button
      disabled={dispatch.isPending}
      onClick={() => dispatch.mutate({ chainId: batchRef.chainId, batcher: batchRef.batcher })}
    >
      Send the batch now
    </button>
  );
}
```

{% endtab %}
{% endtabs %}

## Parameters

```ts
import { type UseVaultMutationOptions } from "@zama-fhe/react-sdk/vaults";
```

## Mutation variables

A `BatcherRef`, passed to `mutate` / `mutateAsync`.

### chainId

`number`

The batcher's chain.

### batcher

`Address`

The batcher whose open batch is dispatched.

```tsx
dispatch.mutate({ chainId: batchRef.chainId, batcher: batchRef.batcher });
```

**Throws:**

* `ChainMismatchError`: the wallet is not on the batcher's chain.
* `TransactionRevertedError`: the dispatch reverted, for example because the batch is too young, the batcher is paused, or a keeper dispatched it first.

## Return Type

The `data` property (after a successful mutation) is a `TransactionResult`: `{ txHash, receipt }`.

When the mutation settles, successful or not, the hook invalidates every vault read and every confidential balance.

## Related

* [useFinalize](https://docs.zama.org/protocol/sdk/api-references/react/usefinalize.md): the next step after dispatch
* [useBatch](https://docs.zama.org/protocol/sdk/api-references/react/usebatch.md): when `dispatch` is available


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.zama.org/protocol/sdk/api-references/react/usedispatch.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
