Skip to content

Add memo extraction helpers to the JS client - #420

Merged
lorisleiva merged 1 commit into
mainfrom
feature/memo-extraction-helpers
Sep 16, 2026
Merged

lorisleiva merged 1 commit into
mainfrom
feature/memo-extraction-helpers

Conversation

@lorisleiva

Copy link
Copy Markdown
Member

This PR adds helpers to the @solana-program/memo JS client for reading memos emitted under any version of the Memo program.

The Memo program has been deployed under several addresses over time (v1, v3 and the current v4), so consumers that filter by a single program address silently miss memos emitted under older versions. This adds getMemosFromInstructions, which matches instructions against every historical address and returns each memo's decoded text, raw bytes, source program address and instruction index.

import { getMemosFromInstructions } from '@solana-program/memo';

const memos = getMemosFromInstructions(transactionMessage.instructions);
// => [
//   { memo: 'Hello world!', bytes: Uint8Array(12), programAddress: 'Memo4c2p…', index: 1 },
// ]

The supported addresses are exposed as a SUPPORTED_MEMO_PROGRAM_ADDRESSES constant, with the legacy addresses available individually as LEGACY_MEMO_PROGRAM_ADDRESS_V1 and LEGACY_MEMO_PROGRAM_ADDRESS_V3. The current address remains the generated MEMO_PROGRAM_ADDRESS, which should still be used when building new memo instructions.

import {
    SUPPORTED_MEMO_PROGRAM_ADDRESSES, // [v1, v3, v4]
    MEMO_PROGRAM_ADDRESS, // v4, for building instructions
} from '@solana-program/memo';

// Filter instructions yourself if you need finer control.
const isMemo = SUPPORTED_MEMO_PROGRAM_ADDRESSES.includes(instruction.programAddress);

New hand-written modules (src/constants.ts, src/memos.ts) live alongside the generated code and are re-exported from src/index.ts. Unit tests cover extraction across all program versions, ordering and index preservation, multi-byte UTF-8, and the empty-data case.

The Memo program has been deployed under several addresses over time (v1, v3 and the current v4), so consumers that filter by a single program address silently miss memos emitted under older versions. This adds getMemosFromInstructions, which matches instructions against every historical address and returns each memo's decoded text, raw bytes, source program address and instruction index.

The supported addresses are exposed as a SUPPORTED_MEMO_PROGRAM_ADDRESSES constant, with the legacy addresses available individually as LEGACY_MEMO_PROGRAM_ADDRESS_V1 and LEGACY_MEMO_PROGRAM_ADDRESS_V3. The current address remains the generated MEMO_PROGRAM_ADDRESS, which should still be used when building new memo instructions.

New hand-written modules (src/constants.ts, src/memos.ts) live alongside the generated code and are re-exported from src/index.ts. Unit tests cover extraction across all program versions, ordering and index preservation, multi-byte UTF-8, and the empty-data case.

@Woody4618 Woody4618 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yay thanks!

@joncinque joncinque left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks!

@lorisleiva
lorisleiva merged commit f1efc71 into main Sep 16, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants