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

# useResumeUnshield

Mutation hook that resumes an unshield interrupted between unwrap and finalize steps.

Mutation hook that resumes an unshield interrupted between the unwrap and finalize steps (e.g. the user closed the page mid-flow).

## Import

```ts
import { useResumeUnshield, useWrappedToken } from "@zama-fhe/react-sdk";
```

## Usage

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

```tsx
import { usePendingUnshield, useResumeUnshield } from "@zama-fhe/react-sdk";
import type { Address } from "@zama-fhe/sdk";

function ResumeUnshieldGuard({
  wrapperAddress,
  children,
}: {
  wrapperAddress: Address;
  children: React.ReactNode;
}) {
  // The SDK persisted the unwrap tx hash during phase 1 and clears it
  // automatically once the resume finalizes; the query invalidates on success.
  const { data: unwrapTxHash } = usePendingUnshield(wrapperAddress);
  const { mutate: resumeUnshield } = useResumeUnshield(wrapperAddress);

  if (unwrapTxHash) {
    // Finalize on user action, not on load — never trigger a wallet tx unprompted.
    return <button onClick={() => resumeUnshield({ unwrapTxHash })}>Resume unshield</button>;
  }

  return children;
}
```

{% endtab %}

{% tab title="config.ts" %}

```ts
// config.ts
import { createConfig as createZamaConfig } from "@zama-fhe/react-sdk/wagmi";
import { web } from "@zama-fhe/sdk/web";
import { sepolia } from "@zama-fhe/sdk/chains";
import type { FheChain } from "@zama-fhe/sdk/chains";
import { config as wagmiConfig } from "./wagmi";

const mySepolia = {
  ...sepolia,
  relayerUrl: "https://your-app.com/api/relayer/11155111",
} as const satisfies FheChain;

export const zamaConfig = createZamaConfig({
  chains: [mySepolia],
  wagmiConfig,
  relayers: { [mySepolia.id]: web() },
});

// In your app layout:
// <ZamaProvider config={zamaConfig}>
//   <App />
// </ZamaProvider>
```

{% endtab %}
{% endtabs %}

## Parameters

### address

`Address`

Address of the confidential wrapper contract. Passed positionally as the first argument.

```ts
const { mutateAsync: resumeUnshield } = useResumeUnshield("0xWrapper");
```

***

## Mutation variables

Passed to `mutate` / `mutateAsync` at call time.

### unwrapTxHash

`Hex`

Transaction hash of the original unwrap transaction. Retrieved via `WrappedToken.getPendingUnshield()` (see [useWrappedToken](https://docs.zama.org/protocol/sdk/api-references/react/usewrappedtoken.md)).

```ts
await resumeUnshield({ unwrapTxHash: "0xabc..." });
```

## Recovery pattern

The SDK persists the unwrap tx hash automatically when phase 1 is submitted and clears it once finalization confirms, so recovery is two steps:

1. [**`usePendingUnshield(tokenAddress)`**](https://docs.zama.org/protocol/sdk/api-references/react/usependingunshield.md) — returns the stored unwrap tx hash (or `null` if none is pending).
2. **`resumeUnshield({ unwrapTxHash })`** — picks up from the finalize step using the unwrap receipt, then clears the persisted state on success (the query invalidates automatically).

Run this check on mount to handle any session that was interrupted. Resuming is intentionally caller-driven — prompt the user rather than finalizing on load, so you never trigger a wallet transaction they did not initiate.

{% hint style="warning" %}
**An already-finalized resume is not a failure.** If the unwrap request was already finalized (another tab, a double click, a third party), the mutation fails with [`UnshieldAlreadyFinalizedError`](https://docs.zama.org/protocol/sdk/api-references/sdk/errors.md#unshieldalreadyfinalizederror). The funds already arrived. The SDK clears the persisted state and the hook invalidates the pending-unshield and balance queries, so the resume prompt disappears on its own. Treat the error as completion; do not retry.
{% endhint %}

{% hint style="info" %}
The SDK persists and clears the pending-unshield state for you. If you bypass `resumeUnshield` and orchestrate `unwrap` + `finalizeUnwrap` (via the `useUnwrap` / `useFinalizeUnwrap` hooks) yourself, manage your own persistence between the two phases.
{% endhint %}

## Return Type

`data` resolves to `{ txHash: Hex, receipt: TransactionReceipt }`.

Auto-invalidates the `confidentialBalance` cache on success.

## Related

* [usePendingUnshield](https://docs.zama.org/protocol/sdk/api-references/react/usependingunshield.md) — detect an interrupted unshield to resume
* [useUnshield](https://docs.zama.org/protocol/sdk/api-references/react/useunshield.md) — standard unshield (handles both steps automatically)
* [useUnshieldAll](https://docs.zama.org/protocol/sdk/api-references/react/useunshieldall.md) — unshield the entire balance
* [WrappedToken.resumeUnshield](https://docs.zama.org/protocol/sdk/api-references/sdk/wrappedtoken.md#resumeunshield) — imperative equivalent on the `WrappedToken` class


---

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