---
id: UC0028
title: "Payroll run reconciliation"
url: https://carbium.sh/library/usecase/payroll-run-reconciliation
collection: Use cases
category: Payouts, payroll and remittance
revision: 1
updated: 2026-11-22
author: Carbium
code: MIT (LICENSE in the zip); text: all rights reserved, Carbium Corporation
---

# Payroll run reconciliation

Match what a payroll run actually paid in USDC against what your ledger says it owed: every transfer out of the treasury, summed per employee wallet, with short, double and missing payments flagged. Includes a read-only Node script over the treasury's recent history.

## What reconciling a run means

After a payroll run goes out, finance needs one answer per employee: did the wallet receive the amount the ledger says, and exactly once. The treasury signed the transfers, so the chain already holds the evidence. Reconciliation reads it back and lines it up with your payroll ledger.

1. Read the treasury's recent signatures.
2. Read each transaction and take the USDC balance change per wallet.
3. Sum the credits per recipient wallet across the run.
4. Compare each sum with the ledger and mark the row paid, short, over, missing or not in the ledger.

Carbium covers the reads: address history and transactions. Your payroll system keeps the ledger and your own signer sends the transfers. The script below only reads.

## From a transfer to a payout line

One payroll transaction can pay a single employee or fifty. It can create token accounts for new hires on the way and carry a memo with the run id. Reading the instructions to see who got what is fragile. A plain USDC transfer names the source token account, the destination token account and the signer. The destination's owner wallet is absent, so the instructions alone cannot say which employee was paid.

The script reads balances. Every transaction carries `preTokenBalances` and `postTokenBalances`, and each entry names the mint, the owner wallet and the amount in base units. Subtract pre from post for the USDC mint and group by owner. An employee whose wallet holds USDC in two token accounts still gets one total, because the script sums changes by owner. The treasury shows a negative change and each employee a positive one.

Amounts stay integer base units in a bigint. USDC has 6 decimals, so the script turns the ledger's decimal text into units once and converts back only when it prints.

## The reconciliation script

Run it with no arguments and it finds a wallet that just paid out USDC, which shows the output shape. Give it the treasury wallet and a ledger file of `wallet,amount` lines and it reconciles the treasury's last 10 signatures. It calls `getSignaturesForAddress` for the treasury and `getTransaction` for each signature.

`main.ts` (run: `CARBIUM_KEY=$CARBIUM_KEY node main.ts [<treasury wallet> [<ledger.csv>]]`)

```ts
// UC0028 · Payroll run reconciliation
// https://carbium.sh/library/usecase/payroll-run-reconciliation
// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.
// SPDX-License-Identifier: MIT

// Read-only payroll reconciliation: sum the USDC a treasury paid out and compare it with a ledger file.
import { address, createDefaultRpcTransport, createSolanaRpcFromTransport, isAddress, type Signature } from "@solana/kit";
import { readFileSync } from "node:fs";

const key = process.env.CARBIUM_KEY;
if (!key) { console.error("Set CARBIUM_KEY to your Carbium API key."); process.exit(1); }
const url = process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh";
const [treasuryArg, ledgerFile] = process.argv.slice(2);
if (treasuryArg !== undefined && !isAddress(treasuryArg)) {
  console.error("Usage: node main.ts [<treasury wallet> [<ledger.csv with wallet,amount lines>]]");
  process.exit(1);
}

const USDC = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"; // USDC on mainnet
const rpc = createSolanaRpcFromTransport(createDefaultRpcTransport({ url, headers: { "x-api-key": key } }));
const units = (s: string) => { const [w = "0", f = ""] = s.trim().split("."); return BigInt(w) * 1_000_000n + BigInt(f.padEnd(6, "0").slice(0, 6)); };
const fmt = (n: bigint) => `${n / 1_000_000n}.${(n % 1_000_000n).toString().padStart(6, "0")}`;

// USDC balance change per owner wallet in one transaction; null when the call has no data for it.
const deltas = async (sig: Signature): Promise<Map<string, bigint> | null> => {
  // finalized: settled pay only
  const tx = await rpc.getTransaction(sig, { commitment: "finalized", encoding: "json", maxSupportedTransactionVersion: 1 }).send();
  if (!tx?.meta) return null;
  const meta = tx.meta;
  const out = new Map<string, bigint>();
  if (meta.err) return out; // a failed transaction moved no USDC
  for (const [list, sign] of [[meta.preTokenBalances, -1n], [meta.postTokenBalances, 1n]] as const)
    for (const b of list ?? []) if (b.mint === USDC && b.owner) out.set(b.owner, (out.get(b.owner) ?? 0n) + sign * BigInt(b.uiTokenAmount.amount));
  return out;
};

let treasury = treasuryArg;
if (!treasury) {
  const recent = await rpc.getSignaturesForAddress(address(USDC), { commitment: "finalized", limit: 40 }).send();
  const t0 = Date.now();
  for (const s of recent) {
    if (s.err) continue; // failed transactions moved no USDC
    if (Date.now() - t0 > 15_000) break; // stop searching after 15 s; pass a treasury wallet instead
    try {
      const payer = [...((await deltas(s.signature)) ?? new Map<string, bigint>())].find(([, v]) => v < 0n);
      if (payer) { treasury = address(payer[0]); break; }
    } catch (e) { console.log(`${s.signature.slice(0, 12)}  read failed: ${e}`); }
  }
  if (!treasury) { console.error("No payer found in the newest USDC transactions, pass a treasury wallet."); process.exit(1); }
  console.log(`no treasury given, using a wallet that just paid out USDC: ${treasury}`);
}
const wallet: string = treasury;

const sigs = await rpc.getSignaturesForAddress(address(wallet), { commitment: "finalized", limit: 10 }).send();
const results = await Promise.allSettled(sigs.map((s) => deltas(s.signature)));
const paid = new Map<string, bigint>();
let unread = 0; // failed or empty reads: the pay may sit in one of them
results.forEach((r, i) => {
  const sig = sigs[i]!.signature;
  if (r.status === "rejected") { unread++; console.log(`${sig.slice(0, 12)}  read failed: ${r.reason}`); return; }
  if (!r.value) { unread++; console.log(`${sig.slice(0, 12)}  no transaction data, counted as unread`); return; }
  if ((r.value.get(wallet) ?? 0n) >= 0n) return; // the treasury paid nothing out in this one
  for (const [owner, d] of r.value) if (owner !== wallet && d > 0n) {
    paid.set(owner, (paid.get(owner) ?? 0n) + d);
    console.log(`${sig.slice(0, 12)}  ${owner}  ${fmt(d)} USDC`);
  }
});

if (!ledgerFile) {
  console.log(`${paid.size} wallets received USDC from ${wallet} in the last ${sigs.length} signatures; pass a ledger file to reconcile`);
  process.exit(0);
}
const ledger = new Map<string, bigint>(); // rows for one wallet are summed
for (const line of readFileSync(ledgerFile, "utf8").split("\n")) {
  const [w = "", a = "0"] = line.split(",");
  if (isAddress(w.trim())) ledger.set(w.trim(), (ledger.get(w.trim()) ?? 0n) + units(a));
}
for (const [w, owed] of ledger) {
  const got = paid.get(w) ?? 0n;
  const status = got === 0n ? "MISSING" : got === owed ? "paid" : got < owed ? `SHORT by ${fmt(owed - got)}` : `OVER by ${fmt(got - owed)}`;
  const doubt = unread > 0 && got < owed ? `  (unverified, ${unread} unread)` : "";
  console.log(`${w}  owed ${fmt(owed)}  received ${fmt(got)}  ${status}${doubt}`);
}
for (const [w, got] of paid) if (!ledger.has(w)) console.log(`${w}  received ${fmt(got)}  NOT IN LEDGER`);
```

Both reads ask for finalized, so only settled pay is counted. `getTransaction` passes `maxSupportedTransactionVersion: 1` because mainnet carries [v1 transactions](https://carbium.sh/docs#rpc).

The ten transactions are read in one `Promise.allSettled`, so a failed call prints its signature and the run goes on. A null answer, which `getTransaction` can return for an older signature that the address index still lists, is printed and counted as unread, and so is a failed call. It is never counted as paid. When that count is above 0, every MISSING and SHORT row is marked unverified, because the pay may sit in a transaction the script could not read.

The script sums ledger rows per wallet when it loads the file, so a salary plus a reimbursement to one wallet is compared as one total and a correct payment never shows as over.

## What a run costs in cells

Cells are the admission charge per call, and [limits are per account](https://carbium.sh/docs#limits), so every key on the account draws on one budget. A reconciliation reads signatures and transactions; the balance read is the optional cross-check below.

| Call | Cells | Free req/s | Dev req/s | Business req/s | Pro req/s |
|---|---|---|---|---|---|
| getSignaturesForAddress | 50 | 0.24 | 1.2 | 100 | 500 |
| getTransaction | 50 | 0.24 | 1.2 | 5 | 25 |
| getTokenAccountBalance | 10 | 0.5 | 15 | 50 | 400 |

One page of 10 signatures plus 10 transactions is 11 calls and 550 cells. A run of 200 employees paid by one transfer each needs 200 `getTransaction` calls, which is 10,000 cells. At the Business rate of 5 req/s that takes 40 s, at Pro's 25 req/s it takes 8 s, and at Dev's 1.2 req/s about 167 s.

A rate class absorbs bursts up to 1,024 cells or one second of its rate, whichever is larger. For `getTransaction` below Pro that is 1,024 cells, so about the first 20 transactions of a read can go out at once. Pro's 25 req/s on `getTransaction` makes the burst 1,250 cells, or 25 transactions. Past the burst, space the reads at your plan's rate. Store each signature you have reconciled, and on the next pass give the last stored one as `until` to `getSignaturesForAddress`, so the same transactions are never read twice.

To check the totals from the other side, `getTokenAccountBalance` on the treasury's USDC token account costs 10 cells. The opening balance minus the ledger total should equal the closing balance when nothing else moved the treasury.

## Matching rules for a run

Each ledger row gets one status, decided from the sum of credits the wallet received from the treasury in the window you read.

- paid: the sum equals the ledger amount to the base unit.
- short: the sum is below the ledger amount, and the difference is the amount still owed.
- over: the sum is above it. A payout sent twice after a retry looks like this, and so does a bonus paid outside the ledger.
- missing: a ledger row with no credit in the window.
- not in ledger: a wallet that received USDC from the treasury with no ledger row, such as an old address, a test transfer or a typo.

The window matters. A run's transfers can spread over several transactions and a few minutes, so reconcile over every signature between the first and last transaction of the run. Ten signatures is a starting page. For a larger run, raise `limit` and pass `before` to step back, one page of the address index at a time.

Match on the wallet and on a payout id you control. The chain carries no employee id. A memo instruction holding the payout id, added when you build the transfer, ties a transaction back to a ledger row later.

## Where it ends

- The chain proves a wallet received USDC. It cannot prove the wallet belongs to the employee, and the wallet column in the ledger is yours to keep correct.
- The script reads one mint, USDC. A run paid in another token needs that mint added to the script; SOL transfers are not read.
- Reconcile inside the 30-day window of getSignaturesForAddress: an empty page past it marks the index's age limit. Record each payout's signature, wallet and amount when you send it, because once a run falls outside the index that stored record is the only evidence.
- Gross transfers only. Withholding, social contributions, payslips and local labor rules belong to your payroll provider, and converting local currency into USDC happens outside Carbium.
- A transaction that failed on chain moved no USDC, so the script skips it. A failed payout shows as missing until you resend it.
- The script only reads and holds no key.

## When it goes wrong

| What goes wrong | What to do |
|---|---|
| getTransaction answers -32015 for some signatures. | Pass maxSupportedTransactionVersion: 1 with the encoding. With the value absent or 0 the call answers -32015 for a v1 transaction. |
| A signature from the page returns null. | The address index lists signatures below the validator's ledger floor, so an older one can have no transaction data. The script counts it as unread and marks MISSING and SHORT rows unverified; read that signature again before chasing the employee. |
| An employee shows OVER by exactly one payout. | Open both signatures. A retry after a timeout is the usual cause. Key every payout by a ledger id and look the first signature up before building a replacement transfer. |
| Totals differ by a cent or less with no visible cause. | An amount went through a float. Keep integer base units in a bigint, convert the ledger once on the way in and format only when printing. |
| A wallet that is an employee shows as not in the ledger. | The ledger holds the USDC token account address instead of the owner wallet, or the employee changed wallets. The script groups by owner wallet, so store the owner address in the ledger. |

## Questions

### Why read token balances and not the transfer instructions?

Instructions come in several shapes, such as a plain transfer, a checked transfer or one payment inside a batch, and each needs its own decoding. The balance entries give the owner and the amount the same way for all of them.

### How do I reconcile a run that crosses two pages of signatures?

Read the first page, pass its oldest signature as `before` on the next call and keep going until a page reaches the run's first transaction. Sum each wallet's credits across every page before comparing, since one wallet's pay can sit on either side of the page edge.

### Can the ledger hold decimal amounts?

Yes. The script reads text such as 1250.50 and converts it to 6-decimal base units once, so no float touches a total.

### Does it handle a run sent as many transactions?

Yes. The script sums each wallet's credits across every signature it reads, so a run split over several transactions reconciles as one.

### Can it check a run paid in more than one token?

Replace the single mint with a set of mints and key the totals by mint and owner. The balance entries carry the mint on every row.

## Related

- [Transaction status check](https://carbium.sh/library/howsolana/transaction-status-check) (How to use Solana, HS0008)
- [Cross-border USDC payouts](https://carbium.sh/library/usecase/cross-border-usdc-payouts) (Use cases, UC0004)
- [carbium.sh/docs#rpc](https://carbium.sh/docs#rpc)
- [carbium.sh/docs#endpoints](https://carbium.sh/docs#endpoints)
- [carbium.sh/docs#auth](https://carbium.sh/docs#auth)
- [carbium.sh/docs#limits](https://carbium.sh/docs#limits)
