library / Use cases / Stablecoin treasury and B2B settlement / UC0149
Unapplied cash queue
A Solana transaction can carry a text message through the Memo program. The reader here pulls those messages from recent transactions and sorts each payment into applied or unapplied, so the treasury team clears the queue.
Yes, through the Memo program
A Solana transaction has no free-form data field of its own. It holds instructions, and each instruction names a program and passes it a byte array. To attach a message, the transaction includes an instruction to the Memo program, and that instruction's data is the text. The program checks that the bytes are valid UTF-8 and writes the text into the transaction log, so the message stays on chain with the rest of the transaction.
Anyone who can read the ledger can read the message. The payer signs the transaction as usual, and the memo rides along in the same signed bytes, so it cannot be changed after signing.
For a stablecoin desk the useful case is the payer's reference: an invoice number, a purchase order or a customer code, sent in the same transaction as the transfer. Payments that arrive with no reference are the ones that wait, unapplied, until someone matches them by hand. The reader below sorts each incoming memo into one of two lists.
What a memo can hold
A memo is free text, and the Memo program does not parse it. Your own code decides what counts as a reference, and the invoice ledger holds the list it matches against.
| What | Where it lives | Limit |
|---|---|---|
| Text message | Memo instruction data | The whole transaction, 1,232 bytes |
| Payment reference | Memo in the transaction that holds the transfer | The same 1,232 bytes |
| Structured fields | Instruction data of a program with its own layout | That program's layout |
| Older memos | Address index on Carbium | 30 days back |
The last row matters most for a queue. A memo older than 30 days is outside what the address index returns, so a queue that starts late has to read older payments from its own ledger.
Read memos into a queue
Each pass reads the newest signatures on the Memo program, then fetches the transactions that are new since the last pass. The RPC methods involved are getSignaturesForAddress and getTransaction. A pass costs one signature call and one transaction read for each new signature, and both cost 50 cells, so the rate table decides how often a plan can run a pass.
- Keep the newest signature you have processed. Stop paging when a page reaches it, so a pass reads only what is new.
- Call getTransaction with maxSupportedTransactionVersion set to 1 and the json encoding. Mainnet carries v1 transactions, and a call without that option answers -32015 for one of them, so the memo would never be read.
- Take the memo from the log. The program writes a line that starts with Program log: Memo (len N), followed by the quoted text. The reader strips that prefix.
- Match the text against your reference format. A match goes to applied, and every other memo stays in the queue for a person to read.
The reader asks for the confirmed commitment on both calls and sets it explicitly. @solana/kit fills in confirmed when a call leaves it out, while the JSON-RPC server defaults to finalized, so setting the value in the code keeps the level visible to whoever reads the script later.
Run the reader
The script takes one optional argument, the number of newest memo transactions to read. With no argument it reads five, and it needs no address, because the Memo program is the account it watches. It prints one line per transaction and a count at the end. A read that fails is printed and skipped, so one bad signature does not stop the pass. Calls go to the RPC endpoint, which the script reads from CARBIUM_RPC_URL.
// UC0149 · Unapplied cash queue// https://carbium.sh/library/usecase/unapplied-cash-queue// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MIT// Read-only reader: lists the newest Memo program transactions and sorts each by its memo text.import { address, createDefaultRpcTransport, createSolanaRpcFromTransport } from "@solana/kit";const apiKey: string = process.env.CARBIUM_KEY ?? "";if (!apiKey) { console.error("Set CARBIUM_KEY to your Carbium API key."); process.exit(1);}const endpoint = process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh";const memoProgram = address("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr");const count = Math.min(Number(process.argv[2] ?? 5), 20);const referencePattern = /INV-\d{4,}/;function connect() { const transport = createDefaultRpcTransport({ url: endpoint, headers: { "x-api-key": apiKey } }); return createSolanaRpcFromTransport(transport);}function memoText(logs: readonly string[]): string { const line = logs.find((entry) => entry.startsWith("Program log: Memo")); return line ? line.replace(/^Program log: Memo \(len \d+\): "?|"$/g, "") : "";}async function main() { const rpc = connect(); const newest = await rpc .getSignaturesForAddress(memoProgram, { limit: count, commitment: "confirmed" }) .send(); console.log(`${newest.length} newest transactions that touched the Memo program`); const outcomes = await Promise.allSettled( newest.map((entry) => rpc .getTransaction(entry.signature, { maxSupportedTransactionVersion: 1, encoding: "json", commitment: "confirmed" }) .send(), ), ); let applied = 0; let queued = 0; for (let index = 0; index < outcomes.length; index++) { const outcome = outcomes[index]!; const label = `${newest[index]!.signature.slice(0, 12)}...`; if (outcome.status === "rejected") { const reason = outcome.reason instanceof Error ? outcome.reason.message : String(outcome.reason); console.log(`${label} read failed: ${reason}`); continue; } if (!outcome.value) { console.log(`${label} no transaction returned`); continue; } const text = memoText(outcome.value.meta?.logMessages ?? []); const hit = referencePattern.test(text); if (hit) applied += 1; else queued += 1; console.log(`${hit ? "applied " : "unapplied"} ${label} memo: ${text || "(none)"}`); } console.log(`applied ${applied}, unapplied ${queued}`);}await main();
run: CARBIUM_KEY=$CARBIUM_KEY node main.ts 5
On a busy day most lines are short memos from other apps. Swap the program address for your receiving account to read only your own payments, and pair that with a scan of the account's signatures for payments that carry no memo at all.
Keys and rate limits
- The key travels in the x-api-key header on every call.
- Limits are per account. Every key on an account draws from one budget, so a second key adds no room.
- A pass of five new memos costs 300 cells: one signature page at 50 cells and five transaction reads at 50 cells each.
- On Free, getSignaturesForAddress and getTransaction each run at 0.24 requests a second. A call over its rate waits once, and past one second it gets a 429 with a retry-after hint. A busy pass on Free will see those, so run the reader on a paid plan if it runs often.
Where it ends
- A memo is public. Anyone who reads the ledger sees it, and nothing in the program encrypts it. Put a reference code in the memo, and leave out names, email addresses and account numbers.
- The queue reads memo transactions only. A payment that carries no memo never reaches it, so the receiving account needs its own signature scan to catch those.
- The address index keeps 30 days. Older payments have to come from your own ledger.
- A getTransaction call can answer null for a signature the index lists, because the index reaches below the validator's ledger floor. The reader counts that as a failed read and moves on, since a retry is unlikely to change the answer.
- The Memo program's newest signatures come from every app that writes a memo. A reference format loose enough to match ordinary text will apply the wrong payments, so make the pattern specific.
- The script only sorts. It applies nothing to an invoice, and posting a match stays in your books.
When it goes wrong
| what goes wrong | what to do |
|---|---|
| The memo reads as empty for a payment that clearly carried one. | The call did not set maxSupportedTransactionVersion. Pass 1 with the json encoding, as the reader does. |
| A pass stops on a null transaction and the queue stalls. | Count the null as a failed read and continue. The index lists older signatures than the ledger keeps, so a null is the expected reply for those, and the queue moves on. |
| A busy pass on a Free key gets 429 on most reads. | Each class has a req/s limit per account. Lower the batch size, run passes less often, or move to a plan with a higher rate for those two methods. |
| Payments without a memo never appear in the queue. | Scan the receiving account's signatures on its own pass and join the results to the memos by signature. |
| A memo with a customer's name or email shows up in the log of every reader. | Memos are public. Use a reference code, and keep personal details in your own records. |
Questions
Can a Solana transaction carry a message without a program?
No field exists for it. The message travels as the instruction data of a call to the Memo program, and the program writes the text into the transaction log.
How long can the message be?
The whole transaction must fit in 1,232 bytes, and the signatures and the transfer take their share first. A reference code of a few dozen characters is a normal size.
Is the message private?
No. The ledger is public, so anyone can read the memo. Use an invoice number and leave out names and account details.
Can the reader go back a year?
No. The address index keeps 30 days, so older payments need your own ledger. A queue starts reading from the day its payments first arrive.