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

# useHasPermit

Query hook that checks whether stored permits cover the requested contract addresses.

Returns `true` if decrypt operations can proceed without a wallet prompt. Returns `false` when no permits exist or the `permitTTL` has expired.

## Import

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

## Usage

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

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

const CONTRACTS = ["0xTokenA", "0xTokenB"] as const;

function AuthGuard() {
  const { data: hasPermit, isLoading } = useHasPermit({ contractAddresses: [...CONTRACTS] });
  const { mutateAsync: grantPermit } = useGrantPermit();

  if (isLoading) return <span>Checking permits...</span>;

  if (!hasPermit) {
    return <button onClick={() => grantPermit([...CONTRACTS])}>Authorize wallet</button>;
  }

  return <span>Permits active — decrypts will not prompt the wallet</span>;
}
```

{% endtab %}

{% tab title="Gated decrypt" %}

```tsx
import { useHasPermit, useGrantPermit, useDecryptValues } from "@zama-fhe/react-sdk";

function GatedDecrypt({
  encryptedValue,
  contractAddress,
}: {
  encryptedValue: string;
  contractAddress: `0x${string}`;
}) {
  const { data: hasPermit } = useHasPermit({ contractAddresses: [contractAddress] });
  const { mutateAsync: grantPermit } = useGrantPermit();
  const { data, isPending } = useDecryptValues(
    [{ encryptedValue, contractAddress }],
    { enabled: !!hasPermit }, // only decrypt once authorized
  );

  if (!hasPermit) {
    return <button onClick={() => grantPermit([contractAddress])}>Authorize</button>;
  }

  if (isPending) return <span>Decrypting...</span>;
  return <output>{data?.[encryptedValue]?.toString()}</output>;
}
```

{% endtab %}
{% endtabs %}

## Parameters

### contractAddresses

`Address[]` — **required**

Contract addresses to check credentials against. Returns `true` only when stored permits cover **all** specified addresses.

```tsx
const { data: hasPermit } = useHasPermit({ contractAddresses: ["0xContractA", "0xContractB"] });
```

An empty list is a no-op: the query is disabled and `data` stays `undefined`, so you can call the hook unconditionally even when there is nothing to check yet.

## options

`Omit<UseQueryOptions<boolean>, "queryKey" | "queryFn">` — **optional**

Standard React Query options forwarded to the underlying query. Pass `{ enabled: false }` to mount the hook in an idle state (no work, no signature while disabled).

{% hint style="warning" %}
**You must gate decrypt queries yourself.** `useDecryptValues` does not automatically wait for permits — if you call it before `useGrantPermit`, the user sees an unexpected wallet popup. Use `useHasPermit` to conditionally enable the decrypt query via `{ enabled: !!hasPermit }` as the second argument, or conditionally render the decrypt component only when `hasPermit` is `true`.
{% endhint %}

## Return Type

```ts
// Returns UseQueryResult<boolean, Error>
```

`data` is a `boolean`:

* `true` -- stored permits cover all specified addresses; decrypts will not prompt the wallet.
* `false` -- no stored permits, or the `permitTTL` has expired. Call [`useGrantPermit`](/protocol/sdk/api-references/react/usegrantpermit.md) to authorize.

## Related

* [Avoid blind-sign wallet popups](/protocol/sdk/guides/encrypt-decrypt.md#gating-useconfidentialbalance) -- gating balance queries to avoid blind-sign popups
* [`useGrantPermit`](/protocol/sdk/api-references/react/usegrantpermit.md) -- pre-authorize contracts with one wallet signature
* [`useRevokePermits`](/protocol/sdk/api-references/react/userevokepermits.md) -- revoke permits
* [Permit Model](/protocol/sdk/concepts/permit-model.md) -- permit lifecycle and TTL configuration


---

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