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

# useEncrypt

Low-level mutation hook that encrypts a plaintext value using the relayer's FHE engine.

Low-level mutation hook that encrypts plaintext values using the relayer's FHE engine. Returns encrypted values and an input proof for on-chain submission.

{% hint style="warning" %}
For **confidential ERC-20 tokens**, use [`useShield`](https://docs.zama.org/protocol/sdk/api-references/react/useshield.md) or [`useConfidentialTransfer`](https://docs.zama.org/protocol/sdk/api-references/react/useconfidentialtransfer.md) — they handle encryption automatically.

Use `useEncrypt` when your smart contract uses FHE types directly (e.g. a confidential voting contract, a sealed-bid auction, or any non-token contract that accepts encrypted parameters).
{% endhint %}

## Import

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

## Usage

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

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

function EncryptValue() {
  const { mutateAsync: encrypt, isPending } = useEncrypt();

  async function handleEncrypt() {
    const { encryptedValues, inputProof } = await encrypt({
      values: [{ value: 1000n, type: "euint64" }],
      contractAddress: "0xContract",
      userAddress: "0xUser",
    });
    // encryptedValues[0] is the encrypted value (0x hex), inputProof is the ZK proof — both contract-ready
  }

  return (
    <button onClick={handleEncrypt} disabled={isPending}>
      {isPending ? "Encrypting..." : "Encrypt"}
    </button>
  );
}
```

{% endtab %}
{% endtabs %}

## Parameters

`useEncrypt` takes no constructor parameters.

## Mutation variables

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

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

### values

`EncryptInput[]`

Array of typed inputs. Each entry specifies a plaintext value and its encrypted FHE type — the `e`-prefixed type names (`ebool`, `euint64`, `eaddress`, etc.).

### contractAddress

`Address`

Address of the contract that will consume the encrypted value.

### userAddress

`Address`

Address of the user performing the encryption.

## Return Type

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

`data` resolves to `{ encryptedValues: EncryptedValue[], inputProof: Hex }` — `0x`-prefixed hex, ready to pass straight into a contract call.

* **`encryptedValues`** — one encrypted value per input.
* **`inputProof`** — the ZK input proof to submit alongside the encrypted values in a contract call.

## Supported FHE Types

Types use the encrypted (`e`-prefixed) FHE type names — a value tagged `euint64` is encrypted to a `euint64` ciphertext on-chain.

| Type       | JS value type         | Range                     |
| ---------- | --------------------- | ------------------------- |
| `ebool`    | `boolean \| 0n \| 1n` | `true`/`false` or `0`/`1` |
| `euint8`   | `bigint`              | 0–255                     |
| `euint16`  | `bigint`              | 0–65535                   |
| `euint32`  | `bigint`              | 0–2³²−1                   |
| `euint64`  | `bigint`              | 0–2⁶⁴−1                   |
| `euint128` | `bigint`              | 0–2¹²⁸−1                  |
| `euint256` | `bigint`              | 0–2²⁵⁶−1                  |
| `eaddress` | `` `0x${string}` ``   | Ethereum address          |

## Related

* [`useShield`](https://docs.zama.org/protocol/sdk/api-references/react/useshield.md) — high-level hook that encrypts and shields in one step
* [`useConfidentialTransfer`](https://docs.zama.org/protocol/sdk/api-references/react/useconfidentialtransfer.md) — high-level hook that encrypts and transfers
* [`useDecryptValues`](https://docs.zama.org/protocol/sdk/api-references/react/usedecryptvalues.md) — reverse operation, decrypt encrypted values back to plaintext
* [Encrypt & Decrypt guide](https://docs.zama.org/protocol/sdk/guides/encrypt-decrypt.md) — full walkthrough with examples


---

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