> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cloak.ag/llms.txt
> Use this file to discover all available pages before exploring further.

# Payroll and batch payouts

> Pay many recipients from a private balance, safely retryable, without exposing amounts between them

Payroll from a private balance is a series of payments, one per recipient. Each payment is its own
transaction, because the recipient is bound into its proof. What Cloak gives you is that the
payments are private, need no wallet prompt each, and can be retried without paying anyone twice.

## Prerequisites

* A private balance that covers the total plus withdrawal fees for recipients paid to public
  addresses. Use `quote` per row to size it.
* For an organization: a business-mode account on a server. See [Backend integration](https://docs.cloak.ag/sdk/backend-integration.md).

## Pay a list of recipients

```ts theme={null}
import { isCloakCallError } from "@cloak.dev/sdk";

interface Row {
  id: string; // your stable row id: employee + period
  to: string; // a cloak_ address (private) or a Solana address (public withdrawal)
  amount: string; // decimal string, in USDC
}

declare const rows: Row[];

const results: Array<{ id: string; status: string; tx?: string; error?: string }> = [];

for (const row of rows) {
  try {
    const receipt = await cloak.send({
      to: row.to,
      token: "USDC",
      amount: row.amount,
      ref: `payroll-2026-11:${row.id}`, // the same ref never pays twice
    });
    results.push({ id: row.id, status: receipt.repeated ? "already paid" : receipt.status, tx: receipt.txs.solana });
  } catch (e) {
    if (!isCloakCallError(e)) throw e;
    results.push({ id: row.id, status: e.retryable ? "retry" : "failed", error: `${e.code}: ${e.message}` });
    if (e.code === "balance.insufficient") break; // stop: the rest will fail the same way
  }
}
console.table(results);
```

Run it again after a crash or a partial failure: rows already paid return their first receipt with
`repeated: true` and move nothing. A row whose earlier attempt started and never recorded its end
throws `ref.unsettled`; reconcile that one by hand before paying it again.

## Private or public recipients

| `to` | What the recipient sees | Fee |
| - | - | - |
| A `cloak_` address | A private note in their Cloak balance | None |
| A Solana address | USDC in their wallet, publicly | The pool's withdrawal fee, added on top |
| A Base, Polygon, Sui or Tron address | USDC (USDT on Tron) on that chain | Withdrawal fee plus the route's delivery cost |

Paying `cloak_` addresses keeps amounts hidden from everyone, including other employees. Paying
public addresses hides who paid, but each amount and recipient is public.

## How fast it runs

`createCloak` runs one money-moving call at a time per account, so a payroll is sequential: each
row proves, submits and confirms before the next starts. Plan for the run to take a while for a long
list, and run it on a server, not in a browser tab.

## Fewer prompts with the low-level API

With `createCloak` there are no wallet prompts to batch: payments are signed by the account. With the
low-level API, each payment needs the wallet to sign a request. `transactBatch` runs up to 64 payments
under one wallet approval, proving in parallel. The SDK recommends chunks of about 25 rows,
because every spend consumes on-chain root history. See [Batch signing](https://docs.cloak.ag/sdk/batch-signing.md).

## Related

* [Backend orchestration example](https://docs.cloak.ag/examples/backend-orchestration.md): a payout worker with a queue.
* [Cross-chain](https://docs.cloak.ag/guides/cross-chain.md): paying out to Base, Polygon, Sui or Tron.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.