services
Get a key

library / How to use Solana / HS0033

Memo instruction reader

One TypeScript file fetches a transaction with getTransaction, finds every Memo program instruction at the top level and among the inner instructions, and prints the text. With no argument it picks recent signatures from the Memo program itself.

By Carbium · History and parsing · HS0033 · updated 2026-11-22

01

Where the memo sits

The Memo program has two ids. Version 2 is MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr and the older version 1 is Memo1UhkJRfHyvLMcVucJwxXeuD728EqVDDwQDxFmNo. A memo is an ordinary instruction: its program id is one of those two and its data is the text as UTF-8 bytes. A transaction has no memo field of its own, so you find the memo by scanning instructions for that program id.

Instructions live in two places. The top-level list is transaction.message.instructions. The inner list is meta.innerInstructions, which holds the calls that programs made while the transaction ran, grouped under the index of the top-level instruction that caused them. A memo added by a wallet or a script is top level. A memo written by another program through a cross-program call shows up only in the inner groups, and a reader that checks the first list alone never sees it.

The encoding you ask for decides how much work is left. With json, programIdIndex always points into the static accountKeys, because a v0 message cannot load an invoked program from a lookup table; only an instruction's account indexes run on into the loaded addresses. The data is base58 that you decode yourself. With base64 the whole transaction arrives as one encoded blob that you deserialize first. With jsonParsed the node resolves the program ids and parses the programs it knows. The Memo program is one of them: its instruction arrives with program set to spl-memo and parsed holding the text as a plain string. The file asks for jsonParsed.

02

The code

Install @solana/kit at 8.6.0, export CARBIUM_KEY and run the file with Node 24, which strips TypeScript types on its own. Pass one signature to read that transaction. Pass nothing and the file takes the newest 100 signatures of the Memo program and keeps up to five that carry a memo, so it has something to read before you have a signature of your own.

main.ts
// HS0033 · Memo instruction reader// https://carbium.sh/library/howsolana/memo-instruction-reader// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MITimport {  address,  createDefaultRpcTransport,  createSolanaRpcFromTransport,  signature,} from "@solana/kit";const apiKey = process.env.CARBIUM_KEY;if (apiKey === undefined || apiKey === "") {  console.error("CARBIUM_KEY is not set.");  process.exit(1);}const endpoint = process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh";const client = createSolanaRpcFromTransport(  createDefaultRpcTransport({ url: endpoint, headers: { "x-api-key": apiKey } }),);const MEMO_V2 = "MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr";const MEMO_IDS = new Set([MEMO_V2, "Memo1UhkJRfHyvLMcVucJwxXeuD728EqVDDwQDxFmNo"]);type Instr = { programId: string; parsed?: unknown; data?: string };// Yield one line per Memo instruction in a list. With jsonParsed the text is in `parsed`.function* memosIn(place: string, instrs: readonly Instr[]): Generator<string> {  for (const [n, ins] of instrs.entries()) {    if (!MEMO_IDS.has(ins.programId)) continue;    const body =      typeof ins.parsed === "string"        ? ins.parsed        : `unparsed, raw base58 data ${ins.data ?? "(none)"}`;    yield `${place}, instruction ${n}: ${body}`;  }}async function readMemos(sig: string): Promise<string[] | null> {  const tx = await client    .getTransaction(signature(sig), {      commitment: "confirmed",      encoding: "jsonParsed",      maxSupportedTransactionVersion: 1,    })    .send();  if (tx === null) return null;  const lines = [...memosIn("top level", tx.transaction.message.instructions)];  for (const grp of tx.meta?.innerInstructions ?? []) {    lines.push(...memosIn(`inner group ${grp.index}`, grp.instructions));  }  return lines;}const arg = process.argv[2];const sigs: string[] = arg  ? [arg]  : (      await client        .getSignaturesForAddress(address(MEMO_V2), { limit: 100, commitment: "confirmed" })        .send()    )      .filter((row) => row.memo !== null)      .slice(0, 5)      .map((row) => row.signature);const settled = await Promise.allSettled(sigs.map(readMemos));settled.forEach((res, i) => {  console.log(sigs[i]);  if (res.status === "rejected") {    console.log(`  failed: ${String(res.reason)}`);  } else if (res.value === null) {    console.log("  no transaction found (older than the ledger?)");  } else if (res.value.length === 0) {    console.log("  no memo instruction");  } else {    res.value.forEach((l) => console.log(`  ${l}`));  }});

run: node main.ts [signature]

memosIn is a generator that walks one instruction list and yields the entries whose programId is a Memo program id. It runs once over the top-level list and once per group in meta.innerInstructions, and each hit is labelled with where it was found. Up to five transactions are fetched together with Promise.allSettled, so one failed fetch is printed and the others still print. A null answer prints its own line and the other signatures still print.

getSignaturesForAddress lists every transaction that names the Memo program as an account, including transactions that pass it to another program which never calls it. The file asks for a page of 100 and keeps up to the first five rows whose memo is not null, so the no-argument run prints real memo text. The filter picks transactions with a top-level memo. A signature passed by hand can still print "no memo instruction" when the program only appears as an account. Both calls read at confirmed commitment.

03

Reading what comes back

Each instruction in a jsonParsed transaction is one of two shapes. Parsed programs carry program and parsed. Programs the node cannot parse carry accounts and a base58 data string instead. Both carry programId, which is why the file filters on it.

FieldWhereMeaning
programIdevery instructionThe program the instruction calls. Compare it with the two Memo ids.
programparsed instructionsThe name the node gives the program, spl-memo for a memo.
parsedparsed instructionsThe memo text as a string.
indexeach inner groupThe position of the top-level instruction that made the inner calls.
dataunparsed instructionsBase58 of the raw bytes. Decode it and print the bytes as hex.

Rows from getSignaturesForAddress have a memo field too, shaped like [5] hello: the byte length in brackets, then the text. When a transaction holds several memos the node joins them with a semicolon. In standard Solana JSON-RPC this field comes from top-level Memo instructions only, so a memo written through a cross-program call leaves it null and only the inner-instruction scan finds it. That field is a quick filter when you list many signatures, and it saves a getTransaction call for each one. It is absent from the transaction itself, so the full read still needs the scan.

$Version 2 also writes the text to the transaction logs, as a line like Program log: Memo (len 5): "hello" in meta.logMessages. Version 1 logs nothing. The logs are a fallback if you read a transaction with an encoding that leaves instructions raw, but the instruction is the source and the log line is a copy.
04

On Carbium

Calls go to https://services.carbium.sh, or to whatever CARBIUM_RPC_URL names. A getTransaction call costs 50 cells. The no-argument run makes one getSignaturesForAddress call at 50 cells and up to five getTransaction calls, 250 cells at most. The two methods sit in different rate classes. The getTransaction calls take at most 250 cells of that class's burst, which is at least 1,024 cells. The getSignaturesForAddress call takes 50 cells of the burst of the address signatures class.

getTransaction in main.ts passes maxSupportedTransactionVersion: 1. Without it, a v1 transaction comes back as error -32015 and the call is uncharged, so a signature that happens to be v1 would print a failed: line and no memo. @solana/kit 8.6.0 accepts the value 1 without a cast. Transaction version error -32015 walks through that error. Transaction explainer decodes every instruction in a transaction.

05

Where it ends

The scan finds instructions that call the Memo program. It finds no memo that a program keeps in its own data or logs. An NFT marketplace that stores a note in its own account, or a program that logs a message, is outside what this file reads.

Discovery by address has a time limit. getSignaturesForAddress on Carbium reaches back 30 days at most, from its own address index. A signature it lists can still come back null from getTransaction when it is older than the ledger the validator holds, so the file handles null, and the no-argument run reads the newest signatures. An empty page past 30 days is the index's age limit and does not mean the program has no older memos.

The text is whatever the sender wrote. The Memo program checks the text only for valid UTF-8 (version 2 also checks that every listed account signed), so a memo can hold any string. Match it against your own records, and confirm a payment from the transfer instruction and its signers.

On its own, a memo says nothing about who wrote it. Version 2 can require extra signers whose accounts are listed on the instruction, and those accounts are what tie a memo to a key. The file prints the text only.

06

When it goes wrong

what goes wrongwhat to do
getTransaction answers null for a signature you hold.The transaction is older than the ledger the validator keeps, or the signature never landed. Read a newer one: run the file with no argument and it takes the newest signatures of the Memo program.
Error -32015 on a transaction.The call left maxSupportedTransactionVersion out, or set it to 0, and the transaction is v1. Pass maxSupportedTransactionVersion: 1.
The file reports no memo for a transaction you know carries one.Check the program id: the memo may come from a program id other than MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr or Memo1UhkJRfHyvLMcVucJwxXeuD728EqVDDwQDxFmNo. Text that some other program logs or stores in its own account is not a Memo instruction, and the scan will not find it. For a version 2 memo, look at meta.logMessages for a Memo (len line.
The memo shows up as raw base58 data and no text.The node parses every Memo instruction whose data is valid UTF-8, so an unparsed one comes from a failed transaction with bytes that are not UTF-8. Decode the data string from base58 and print the raw bytes as hex.
The run prints your argument followed by a failed: line that names a signature error.signature() runs inside readMemos, so the bad string becomes a rejected promise that Promise.allSettled catches and no request is sent for it. A signature is 64 bytes, about 87 or 88 base58 characters. A shorter string is an address, and this file takes none.
07

Questions

Does the getTransaction result have a memo field?

No. The memo is an instruction like any other, found by its program id. Only the rows of getSignaturesForAddress have a memo field, in the form [length] text.

Can one transaction hold more than one memo?

Yes. Each memo is its own instruction, at the top level or inside an inner group, and the file prints all of them with their position.

Why jsonParsed and not json?

With json you look up programIdIndex in accountKeys and decode the base58 data yourself. jsonParsed hands you the program id and the text directly.