> 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).

# useBatchDecryptBalancesAs

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`](/protocol/sdk/api-references/react/usedecryptbalanceas.md) -- single-token variant
* [`useDelegationStatus`](/protocol/sdk/api-references/react/usedelegationstatus.md) -- check delegation status before decrypting
* [Delegated Decryption](/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 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/usebatchdecryptbalancesas.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.
