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

# useApproveUnderlying

Low-level escape hatch that approves the wrapper contract to spend the underlying ERC-20.

Approve the confidential wrapper contract to spend the underlying ERC-20. Defaults to a max `uint256` approval. When required — as tokens like USDT demand — it first resets an existing non-zero allowance to zero.

{% hint style="warning" %}
This is a low-level escape hatch for pre-approving outside a shield call. Product code should prefer [`useShield`](/protocol/sdk/api-references/react/useshield.md), which validates the ERC-20 balance, manages approvals, and submits the shield in a single call. Don't combine `useApproveUnderlying` with [`useWrap`](/protocol/sdk/api-references/react/usewrap.md) to recreate `useShield` by hand.
{% endhint %}

## Import

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

## Usage

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

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

function ApproveButton() {
  const { mutateAsync: approve, isPending, error } = useApproveUnderlying("0xWrapper");

  async function handleApprove() {
    // Omit `amount` for a max approval, or pass an exact amount.
    const { txHash } = await approve({ amount: 1000n });
    console.log("Approved in", txHash);
  }

  return (
    <button onClick={handleApprove} disabled={isPending}>
      {isPending ? "Approving..." : "Approve"}
    </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: approve } = useApproveUnderlying("0xWrapper");
```

***

## Mutation variables

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

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

### amount

`bigint | undefined`

Amount of the underlying ERC-20 to approve, in its base units. Omit for a max (`type(uint256).max`) approval.

```ts
await approve({}); // max approval
await approve({ amount: 1000n }); // exact amount
```

**Throws:**

* `SigningRejectedError` -- if the user rejects the wallet prompt
* `TransactionRevertedError` -- if the approval 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 `underlyingAllowance` cache on success.

## Related

* [useShield](/protocol/sdk/api-references/react/useshield.md) -- recommended path; handles approval and wrapping in one call
* [useWrap](/protocol/sdk/api-references/react/usewrap.md) -- wrap already-approved underlying into confidential tokens
* [useUnderlyingAllowance](/protocol/sdk/api-references/react/useunderlyingallowance.md) -- read the current allowance (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/useapproveunderlying.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.
