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

# useBatchDecryptBalancesAs

Mutation hook that decrypts confidential balances across multiple tokens as a delegate.

Mutation hook that decrypts a delegator's confidential balances across multiple tokens in a single call. Uses `Token.batchDecryptBalancesAs` under the hood with caching, concurrency control, and per-token error handling.

## Import

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

## Usage

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

```tsx
import { useMemo } from "react";
import { useBatchDecryptBalancesAs, useZamaSDK } from "@zama-fhe/react-sdk";

function PortfolioBalance({
  tokenAddresses,
  delegatorAddress,
}: {
  tokenAddresses: `0x${string}`[];
  delegatorAddress: `0x${string}`;
}) {
  // Build Token instances using the SDK factory (not hooks — hooks cannot be called in a loop)
  const sdk = useZamaSDK();
  const tokens = useMemo(
    () => tokenAddresses.map((addr) => sdk.createToken(addr)),
    [sdk, tokenAddresses],
  );

  const {
    mutateAsync: batchDecryptAs,
    data: balances,
    isPending,
  } = useBatchDecryptBalancesAs(tokens);

  async function handleDecrypt() {
    await batchDecryptAs({ delegatorAddress });
  }

  return (
    <div>
      <button onClick={handleDecrypt} disabled={isPending}>
        {isPending ? "Decrypting..." : "Decrypt all"}
      </button>
      {balances &&
        Array.from(balances).map(([address, balance]) => (
          <div key={address}>
            {address}: {balance.toString()}
          </div>
        ))}
    </div>
  );
}
```

{% endtab %}
{% endtabs %}

## Parameters

### tokens

`Token[]`

Array of `Token` instances to decrypt balances for. Passed as the first argument to `useBatchDecryptBalancesAs`.

```ts
const { mutateAsync: batchDecryptAs } = useBatchDecryptBalancesAs(tokens);
```

***

## Mutation variables

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

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

### delegatorAddress

`Address`

The address that delegated decryption rights.

### encryptedValues

`EncryptedValue[] | undefined`

Pre-fetched encrypted values. When omitted, they are fetched from the chain.

### accountAddress

`Address | undefined`

The address whose on-chain balance to read. Defaults to `delegatorAddress`.

### maxConcurrency

`number | undefined`

Maximum number of concurrent decrypt calls. Default: `Infinity`.

### onError

`(error: Error, address: Address) => bigint`

Called when decryption fails for a single token. Return a fallback value.

```ts
await batchDecryptAs({
  delegatorAddress: "0xDelegator",
  maxConcurrency: 3,
  onError: (err, addr) => {
    console.error(addr, err);
    return 0n;
  },
});
```

## Return Type

`data` resolves to `Map<Address, bigint>` — a map from each token address to its decrypted balance.

## Related

* [`useDecryptBalanceAs`](https://docs.zama.org/protocol/sdk/api-references/react/usedecryptbalanceas.md) -- single-token variant
* [`useDelegationStatus`](https://docs.zama.org/protocol/sdk/api-references/react/usedelegationstatus.md) -- check delegation status before decrypting
* [Delegated Decryption](https://docs.zama.org/protocol/sdk/api-references/sdk/delegation.md) -- SDK reference


---

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