library / Use cases / Payouts, payroll and remittance / UC0098
Required-memo recipient check
A read-only Node check that lists which Token-2022 token accounts refuse incoming transfers without a memo, so a payout puts a Memo instruction ahead of the transfer. It also covers what no read can tell you: exchange deposit tags.
Two kinds of memo requirement
A payout that needs a memo can hit two different rules, and they share only the word. The first lives on chain. The owner of a Token-2022 token account can switch on the memo-transfer extension. From then on the token program rejects any incoming Transfer or TransferChecked unless the instruction directly before it in the same transaction is a call to the Memo program. The rejection is a token program error, so the whole transaction fails and nothing moves.
The second rule lives at an exchange or custodian. Many of them credit every deposit to one shared address and read a tag from the memo to find the customer. Nothing on chain says the address expects one. The wallet is an ordinary account, the transfer lands, and the funds sit unmatched until someone at the exchange finds them.
| Rule | Where it is kept | Readable on chain | If you ignore it |
|---|---|---|---|
| Required memo on a token account | The token account's own data | Yes | The transfer is rejected |
| Exchange deposit tag | The exchange's ledger | No | The transfer lands and is not credited |
Your software can check the first rule before every run. The second comes from the recipient, usually as a field on a withdrawal form, and your payout record has to store it for each recipient.
Reading the memo flag
The flag sits in the token account's extension list. With jsonParsed encoding, getMultipleAccounts returns a Token-2022 account as parsed JSON, and a required memo shows up as an extension named memoTransfer whose state has requireIncomingTransferMemos set to true. An account with no such extension has no requirement, and a classic Token program account has no memo flag at all.
The script needs no arguments. It asks getSignaturesForAddress for the newest signatures on the Token-2022 program, skips failed ones, and reads the newest successful transaction with getTransaction at maxSupportedTransactionVersion: 1. Mainnet carries v1 transactions, and a value of 0 or none answers -32015 for one. The script collects the token accounts named in the program's parsed instructions, inner ones included, reads up to 100 of them in one getMultipleAccounts call, and prints a yes or no line for each. Pass token account addresses as arguments to check your own recipients instead.
// UC0098 · Required-memo recipient check// https://carbium.sh/library/usecase/required-memo-recipient-check// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MIT// Reads the memo requirement on Token-2022 token accounts: from the newest transactions on the program, or from addresses you pass.import { address, createDefaultRpcTransport, createSolanaRpcFromTransport, isAddress } 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 rpc = createSolanaRpcFromTransport(createDefaultRpcTransport({ url, headers: { "x-api-key": key } }));const TOKEN_2022 = "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb";type Ix = { programId?: string; parsed?: { info?: Record<string, unknown> } };type Tx = { transaction: { message: { instructions: Ix[] } }; meta?: { innerInstructions?: { instructions: Ix[] }[] | null } } | null;type Acc = { parsed?: { type?: string; info?: { owner?: string; extensions?: { extension: string; state?: { requireIncomingTransferMemos?: boolean } }[] } } };const picked = process.argv.slice(2);if (picked.length > 100 || !picked.every((a) => isAddress(a))) { console.error("Usage: node main.ts [<token account> ...] (at most 100; none means the newest Token-2022 transaction)"); process.exit(1);}const keys = new Set<string>(picked);if (keys.size === 0) { const sigs = await rpc.getSignaturesForAddress(address(TOKEN_2022), { limit: 20 }).send() .catch((e: unknown) => { console.error(`getSignaturesForAddress failed: ${e}`); return process.exit(1); }); for (const s of sigs) { if (s.err) continue; const tx = (await rpc.getTransaction(s.signature, { encoding: "jsonParsed", maxSupportedTransactionVersion: 1 }).send() .catch((e: unknown) => { console.log(`getTransaction ${s.signature} failed: ${e}`); return null; })) as unknown as Tx; if (!tx) continue; const ixs = [...tx.transaction.message.instructions, ...(tx.meta?.innerInstructions ?? []).flatMap((i) => i.instructions)]; for (const ix of ixs) { if (ix.programId !== TOKEN_2022) continue; for (const f of ["source", "destination", "account"]) { const v = ix.parsed?.info?.[f]; if (typeof v === "string") keys.add(v); } } if (keys.size > 0) { console.log(`read transaction ${s.signature} at slot ${s.slot}`); break; } }}const list = [...keys].slice(0, 100);if (list.length === 0) { console.log("no Token-2022 token accounts in the newest transactions"); process.exit(0); }const { value } = await rpc.getMultipleAccounts(list.map((a) => address(a)), { encoding: "jsonParsed" }).send() .catch((e: unknown) => { console.error(`getMultipleAccounts failed: ${e}`); return process.exit(1); });let yes = 0, no = 0, other = 0;value.forEach((acc, i) => { const p = acc && acc.owner === TOKEN_2022 ? (acc.data as unknown as Acc).parsed : undefined; if (p?.type !== "account") { other++; console.log(`${list[i]} not a Token-2022 token account`); return; } const required = p.info?.extensions?.some((e) => e.extension === "memoTransfer" && e.state?.requireIncomingTransferMemos === true) ?? false; if (required) yes++; else no++; console.log(`${list[i]} owner ${p.info?.owner ?? "?"} memo required: ${required ? "yes" : "no"}`);});console.log(`memo required yes ${yes}, no ${no}, other ${other}`);
run: CARBIUM_KEY=$CARBIUM_KEY node main.ts [token account ...]
No call sets a commitment, so @solana/kit 8.6.0 reads at confirmed. The owner can switch the flag at any time, so a run ahead of a payout is a snapshot, and you read the account again just before you sign. The flag belongs to the token account. A wallet can own more than one token account for one mint, so check the account the transfer will go to.
The call stops at 100 keys on every plan. getMultipleAccounts takes up to 300 pubkeys on Pro, and below Pro the 1024-cell burst caps a call at 100.
What the reads cost
Each call is charged a fixed number of cells.
| Call | Cells |
|---|---|
| getSignaturesForAddress | 50 |
| getTransaction | 50 |
| getMultipleAccounts, per pubkey | 10 |
A run that finds its accounts in the first transaction it reads costs 50 for the signatures, 50 for the transaction and 1000 for 100 pubkeys, or 1001 for that last call when the request body passes 4 KiB. A call of 1000 cells fits inside the 1,024-cell burst, which is why 100 is the ceiling below Pro. The rate limits for the account-read class are 0.5 req/s on Free, 15 on Dev, 50 on Business and 400 on Pro.
Placing the memo ahead of the transfer
When a recipient's line says yes, build the transaction with the Memo instruction directly ahead of that recipient's transfer. The token program looks at the instruction just before the transfer, so a memo at the start of the transaction does not help when other instructions sit in between. In a batch with several transfers, each flagged recipient needs its own memo instruction immediately before its own transfer. A recipient with no flag can sit anywhere in the batch.
- Keep each flagged recipient's memo and transferChecked as an adjacent pair, and order the pairs freely.
- The memo text is public and permanent. Put a payout id that points into your ledger, never a name or an amount owed.
- Memo bytes count against the 1232-byte cap of a legacy or v0 transaction, so a batch of flagged recipients holds fewer transfers than one without memos.
- For an exchange tag, put the tag in the memo in the format the exchange gives you, together with nothing the exchange would have to strip.
To read a memo back after the payout, see the Memo instruction reader. To go from a wallet to its token accounts first, see Token accounts by owner.
Where it ends
- Exchange deposit tags come from the recipient. No read shows them, so store the tag with each recipient at onboarding and ask when you are unsure.
- Classic Token program accounts have no memo flag. A yes or no here only exists for Token-2022 accounts.
- The flag is read at one moment, and the owner can switch it on after that.
- The check says whether a memo is required. It cannot tell whether the memo text is what the recipient expects.
- The script takes token account addresses. It does not derive them from wallets, and the accounts it finds on its own are a sample from the newest transactions, so its totals say nothing about how common the flag is across the program.
- Carbium builds and signs nothing here. The transfer and memo instructions live in your software.
When it goes wrong
| what goes wrong | what to do |
|---|---|
| getTransaction answers -32015. | Mainnet carries v1 transactions. Pass maxSupportedTransactionVersion: 1 together with an encoding on getTransaction and getBlock. |
| A transfer is rejected even though the transaction holds a memo. | The memo has to be the instruction directly before the transfer. Move it next to the transfer it belongs to, and give each flagged recipient its own memo. |
| An account read as no earlier and now rejects transfers. | The owner switched the requirement on after your read. Read the account again right before signing, and build the pair with a memo for any account that now says yes. |
| A call with more than 100 pubkeys does not fit below Pro. | The 1024-cell burst caps a getMultipleAccounts call at 100 pubkeys below Pro. Send recipients in calls of 100. |
| An exchange deposit lands on chain and is never credited. | The tag was missing or wrong. Keep the signature, send it with the tag to the exchange's support, and store the tag per recipient so the next payout carries it. |
| A line prints as not a Token-2022 token account. | The address is a wallet, a mint, a closed account or a classic Token program account. Check the account's owner, and look up the wallet's token accounts first. |
Questions
Can I read an exchange's memo requirement from the chain?
No. The exchange keeps it in its own ledger, and the deposit address looks like any other account. Take the tag from the recipient or from the exchange's deposit screen.
Does the memo text have to match anything?
The token program checks that the previous instruction is a call to the Memo program. The text is yours, so use an id you can find in your ledger.
Does one flag cover every token account of a wallet?
No. The memo-transfer extension sits on each token account separately, and a wallet can own several for one mint. Read the account you are sending to.
How do I get from a recipient wallet to the account to check?
List its Token-2022 token accounts with getTokenAccountsByOwner, or derive its associated token account, then pass those addresses to the script.