---
id: UC0101
title: "Per-recipient remittance advice"
url: https://carbium.sh/library/usecase/per-recipient-remittance-advice
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
---

# Per-recipient remittance advice

Pay many wallets from one program account in a single transaction, then give each recipient an advice record of their own. A read-only Node script splits a landed USDC transaction into one JSON record per credited owner.

## One program account, many recipients

A payroll or remittance program keeps its funds in token accounts owned by a program derived address, a PDA. No private key exists for a PDA, so the program signs for it from inside the transaction: it hands its seeds to the token program with each transfer instruction, and the runtime accepts that as the owner's signature. One transaction can hold a transfer instruction for every recipient, all drawing on the same program account.

To send, the program makes one `invoke_signed` transfer per recipient, passing the PDA's signer seeds with each call. Each recipient's token account must already exist, or be created in the same transaction by an idempotent associated-token-account create that the fee payer funds. The size of the packet bounds how many recipients fit, address lookup tables relieve that bound, and the account-lock limit and the compute budget cap it after that.

The transaction carries the fee payer's signature, plus the authority's when the program asks for one, which is often the same key. When it lands, every recipient has been paid. When it fails, none has. The transfer instructions and the PDA signing live in your program and your sender, and the script below reads what landed.

The accounting side is where the work starts. One signature covers every recipient, so the signature alone is a poor receipt: an accountant, a support desk or the recipient asking where their money is needs a record that names them. Each recipient needs an advice record of their own, and the only reliable source is the transaction as it landed.

## What an advice record holds

A record is one JSON object per credited owner. The fields are small and all of them come from one `getTransaction` answer.

- signature: the transaction signature, shared by every record of one run.
- payer: the owner of the token account that lost the most USDC, which is the program's PDA in a payroll run.
- recipient: the owner wallet of the token account that gained.
- tokenAccount: the token account that received the funds.
- mint: the USDC mint.
- amount: the base units that arrived, as a string. USDC has 6 decimals, and a string keeps large amounts exact in JSON.
- slot and time: the slot the transaction landed in and its block time as an ISO timestamp.

Signature plus recipient is a natural key for your own table. A wallet paid twice inside one transaction gets one merged record, so the key stays unique.

## Splitting one transaction by balance change

The tempting way to find recipients is to read the transfer instructions. A token transfer into an existing token account lists the token accounts and the sender's authority, and the transfer never names the receiving wallet. The program may also move the funds through inner instructions, which a top-level read misses.

The transaction's metadata has a better source. It lists token balances before and after the transaction, and each entry carries an account index, the mint, the owner wallet and the amount. Subtract the pre amount from the post amount for each token account and every positive difference is a credit, with the owner already named. A token account created inside the same transaction has no pre entry, so its pre amount counts as zero.

Three situations fall out of the same rule. A wallet that owns more than one token account for the mint is merged into one record, with one map keyed by owner. A payer account shows as the largest debit. A transfer-fee mint credits less than was sent, and the record shows what arrived.

> A v1 transaction needs `maxSupportedTransactionVersion: 1` on the call. Without it, or with 0, getTransaction answers -32015, uncharged. See [the version error](https://carbium.sh/library/howsolana/transaction-version-error-32015) for the full case.

## Scanning the newest USDC transactions

The script needs no arguments. It asks the [RPC endpoint](https://carbium.sh/docs/endpoints) at `https://services.carbium.sh`, or at `CARBIUM_RPC_URL` when it is set, for the five newest signatures that mention the USDC mint, then fetches each with `getTransaction` inside its own try. A failed or empty answer is printed and skipped. Both calls read at confirmed commitment.

It keeps the transaction that credits the most owners and prints one JSON line per owner. Many of the newest transactions on the mint credit only one or two owners, so the scan keeps the best of five. For a real payout, replace the mint scan with the signature your sender wrote down before it sent.

`main.ts` (run: `CARBIUM_KEY=$CARBIUM_KEY node main.ts`)

```ts
// UC0101 · Per-recipient remittance advice
// https://carbium.sh/library/usecase/per-recipient-remittance-advice
// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.
// SPDX-License-Identifier: MIT

// Read-only: split one landed USDC transaction into a remittance advice record per credited owner.
import { address, createDefaultRpcTransport, createSolanaRpcFromTransport } from "@solana/kit";

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 MINT = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"; // USDC on mainnet
const rpc = createSolanaRpcFromTransport(createDefaultRpcTransport({ url, headers: { "x-api-key": key } }));

type Bal = { accountIndex: number; mint: string; owner?: string; uiTokenAmount: { amount: string } };
type Change = { owner: string; delta: bigint };

// Post minus pre per token account, USDC only. A new account has no pre entry, so it counts from zero.
const changes = (pre: readonly Bal[], post: readonly Bal[]) => {
  const out = new Map<number, Change>();
  for (const [list, sign] of [[post, 1n], [pre, -1n]] as const) {
    for (const b of list) {
      if (b.mint !== MINT || !b.owner) continue;
      const c = out.get(b.accountIndex) ?? { owner: b.owner, delta: 0n };
      c.delta += sign * BigInt(b.uiTokenAmount.amount);
      out.set(b.accountIndex, c);
    }
  }
  return out;
};

const sigs = await rpc.getSignaturesForAddress(address(MINT), { limit: 5, commitment: "confirmed" }).send();
let best: { signature: string; lines: string[] } | null = null;

for (const s of sigs) {
  if (s.err) continue;
  try {
    const tx = await rpc.getTransaction(s.signature, { commitment: "confirmed", encoding: "jsonParsed", maxSupportedTransactionVersion: 1 }).send();
    if (!tx || !tx.meta) { console.error(`${s.signature}: no transaction returned`); continue; }
    const keys = tx.transaction.message.accountKeys as unknown as { pubkey: string }[];
    const ch = changes(tx.meta.preTokenBalances ?? [], tx.meta.postTokenBalances ?? []);
    let payer = "", drop = 0n;
    for (const c of ch.values()) if (c.delta < drop) { drop = c.delta; payer = c.owner; }
    const owners = new Map<string, { amount: bigint; account: string; top: bigint }>();
    for (const [idx, c] of ch) {
      if (c.delta <= 0n || c.owner === payer) continue;
      const o = owners.get(c.owner) ?? { amount: 0n, account: "", top: 0n };
      o.amount += c.delta;
      if (c.delta > o.top) { o.top = c.delta; o.account = keys[idx].pubkey; }
      owners.set(c.owner, o);
    }
    if (owners.size > (best?.lines.length ?? 0)) {
      const time = tx.blockTime === null ? null : new Date(Number(tx.blockTime) * 1000).toISOString();
      best = {
        signature: s.signature,
        lines: [...owners].map(([recipient, o]) => JSON.stringify({
          signature: s.signature, payer, recipient, tokenAccount: o.account,
          mint: MINT, amount: o.amount.toString(), slot: tx.slot.toString(), time,
        })),
      };
    }
  } catch (e) {
    console.error(`${s.signature}: ${e instanceof Error ? e.message : e}`);
  }
}

if (!best) console.log("no transaction with a credited owner in the newest signatures");
else {
  console.error(`kept ${best.signature} with ${best.lines.length} credited owners`);
  for (const line of best.lines) console.log(line);
}
```

The payer is the owner behind the largest debit, and the recipient list is every other owner with a positive change. Amounts stay bigint until they are written as strings.

## What a scan costs

Both methods are charged 50 cells. One run is one `getSignaturesForAddress` and up to five `getTransaction` calls, so 300 cells, which sits inside the [1,024-cell burst](https://carbium.sh/docs/limits) a rate class absorbs.

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

The cost follows the number of transactions. One `getTransaction` of 50 cells returns the balances of every recipient in it, so a run that pays 20 wallets in one transaction needs one fetch for 20 records. The calls are reads and sign nothing.

## Where it ends

- Packet size bounds the recipients first, because every transfer puts its recipient's token account in the transaction. Lookup tables relieve that bound, and the account-lock limit and the compute budget cap it after that. A large payroll becomes several transactions with records for each. The [size checker](https://carbium.sh/library/howsolana/transaction-size-checker) shows how close a built transaction is.
- A failed transaction pays none. All transfers revert together, and the script skips signatures with an error. The fee is still charged, and no advice record exists for a run that did not pay.
- The script reads USDC only. A payout in another mint needs the mint constant changed, and native SOL payouts move lamport balances, which the script does not read.
- The payer is the largest debit. A transaction that draws on several sources lists only the biggest as payer.
- History: `getSignaturesForAddress` reaches back 30 days at most, and its pages can list a signature that `getTransaction` then answers with null. Write each record to your own table when the transaction lands.
- Records show balance changes. A recipient whose credit and debit cancel inside one transaction shows no record.

## When it goes wrong

| What goes wrong | What to do |
|---|---|
| getTransaction answers -32015 for a transaction that landed. | Pass maxSupportedTransactionVersion: 1 with the encoding. Absent or 0, a v1 transaction is refused, and the call is uncharged. |
| getTransaction returns null for a signature that getSignaturesForAddress listed. | The address index reaches below the validator's ledger floor, so older signatures can be listed without being readable. Handle null, skip it and keep the record you wrote when the transaction landed. |
| Recipients are missing because the code looked for them in the account keys. | A transfer to an existing token account lists token accounts, never the receiving wallet. Read the owner from the pre and post token balances. |
| One wallet appears twice in the records. | A wallet can own more than one token account for the mint. Merge the credits by owner and keep the token account with the largest credit as the record's account. |
| A record is written for a transaction that paid nobody. | Check that err is null before building records. A failed transaction reverts every transfer and still pays its fee. |

## Questions

### Can one signature really pay many wallets from a PDA?

Yes. The fee payer signs the transaction, the program's authority signs too when the program asks for it, and the program signs for the PDA with its seeds on each transfer instruction. All transfers land together or none does.

### How many recipients fit in one transaction?

Packet size decides first and lookup tables relieve it, then the account-lock limit and the compute budget cap it. Each recipient adds a token account and an instruction, so measure the built transaction with a [size checker](https://carbium.sh/library/howsolana/transaction-size-checker) and split the run when it grows past the cap.

### Why read balance changes and skip the instructions?

The instruction lists the token accounts, never the receiving wallet. The balance entries carry the owner, and they also cover transfers the program makes through inner instructions.

### Where should the records live?

In your own table, keyed by signature and recipient. Carbium's address history keeps up to 30 days, so a record you need for a payroll audit later has to be stored when the transaction lands.

## Related

- [Payroll run reconciliation](https://carbium.sh/library/usecase/payroll-run-reconciliation) (Use cases, UC0028)
- [Transaction version error -32015](https://carbium.sh/library/howsolana/transaction-version-error-32015) (How to use Solana, HS0012)
- [carbium.sh/docs/rpc](https://carbium.sh/docs/rpc)
- [carbium.sh/docs/limits](https://carbium.sh/docs/limits)
- [carbium.sh/docs/endpoints](https://carbium.sh/docs/endpoints)
- [carbium.sh/docs/errors](https://carbium.sh/docs/errors)
