> 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/usefinalize.md). Agents can also search and read this documentation through its [MCP server](https://docs.zama.org/protocol/~gitbook/mcp).

# useFinalize

Mutation hook that settles a dispatched vault batch.

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

Any account may send it. Past the batch's `cancelsAt`, the same call cancels the batch instead of settling it.

## Import

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

## Usage

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

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

function SettleButton({ batchRef }: { batchRef: BatchRef }) {
  const { data: batch } = useBatch(batchRef);
  const finalize = useFinalize();

  if (batch?.state !== "dispatched") return null;

  const pastDeadline = batch.cancelsAt <= batch.observedAt;

  return (
    <button disabled={finalize.isPending} onClick={() => finalize.mutate(batchRef)}>
      {pastDeadline ? "Cancel and get it back" : "Settle"}
    </button>
  );
}
```

{% endtab %}
{% endtabs %}

## Parameters

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

## Mutation variables

A [`BatchRef`](https://docs.zama.org/protocol/sdk/api-references/sdk/vaultclient.md#batchref), passed to `mutate` / `mutateAsync`.

### chainId

`number`

The chain of the batch to finalize.

### batcher

`Address`

The batcher of the batch to finalize.

### batchId

`bigint`

The batch to finalize.

```tsx
finalize.mutate({ chainId: 1, batcher: "0xAlphaDeposit", batchId: 7n });
```

**Throws:**

* `VaultBatchNotDispatchedError`: the batch is not dispatched, for example because a keeper already finalized it. The error's `state` says which state it is in.
* `ChainMismatchError`: the wallet is not on the batch's chain.

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

* [Building a vault UI](https://docs.zama.org/protocol/sdk/vaults/building-a-ui.md#dispatched): when to offer it
* [useClaim](https://docs.zama.org/protocol/sdk/api-references/react/useclaim.md): claim once the batch is finalized


---

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