> 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/usewrap.md).

# useWrap

Low-level escape hatch that wraps already-approved underlying ERC-20 into confidential tokens.

Wrap already-approved underlying ERC-20 into confidential tokens.

{% hint style="warning" %}
This is a low-level escape hatch for splitting shield across two signatures: call [`useApproveUnderlying`](/protocol/sdk/api-references/react/useapproveunderlying.md) first, then this. Product code should prefer [`useShield`](/protocol/sdk/api-references/react/useshield.md), which routes and orchestrates the approval in one call. Don't combine `useApproveUnderlying` + `useWrap` to recreate `useShield` by hand.
{% endhint %}

## Import

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

## Usage

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

```tsx
import { useApproveUnderlying, useWrap } from "@zama-fhe/react-sdk";

function WrapButton() {
  const { mutateAsync: approve } = useApproveUnderlying("0xWrapper");
  const { mutateAsync: wrap, isPending } = useWrap("0xWrapper");

  async function handleWrap() {
    await approve({ amount: 1000n });
    const { txHash } = await wrap({ amount: 1000n });
    console.log("Wrapped in", txHash);
  }

  return (
    <button onClick={handleWrap} disabled={isPending}>
      {isPending ? "Wrapping..." : "Wrap"}
    </button>
  );
}
```

{% 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: wrap } = useWrap("0xWrapper");
```

***

## Mutation variables

```ts
import { type WrapParams } from "@zama-fhe/sdk/query";
```

The function passed to `mutate` / `mutateAsync` accepts:

### amount

`bigint`

Amount of the public ERC-20 to wrap, in the token's base units.

### to

`Address | undefined`

Recipient of the confidential tokens. Defaults to the signer address.

### onWrapSubmitted

`((txHash: Hex) => void) | undefined`

Fires with the wrap transaction hash once submitted.

```ts
await wrap({ amount: 1000n, onWrapSubmitted: (txHash) => updateUI(`Wrap: ${txHash}`) });
```

**Throws:**

* `SigningRejectedError` -- if the user rejects the wallet prompt
* `InsufficientERC20BalanceError` -- if the ERC-20 balance is less than the amount
* `InsufficientAllowanceError` -- if the allowance is less than the amount (approve first)
* `TransactionRevertedError` -- if the wrap transaction reverts

## Return Type

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

* **`txHash`** -- Transaction hash submitted to the network.
* **`receipt`** -- Confirmed transaction receipt from the chain.

Auto-invalidates the `confidentialBalance` cache on success.

## Related

* [useShield](/protocol/sdk/api-references/react/useshield.md) -- recommended path; handles approval and wrapping in one call
* [useApproveUnderlying](/protocol/sdk/api-references/react/useapproveunderlying.md) -- approve the wrapper before wrapping
* [useConfidentialBalance](/protocol/sdk/api-references/react/useconfidentialbalance.md) -- auto-invalidated on success


---

# 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.zama.org/protocol/sdk/api-references/react/usewrap.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.
