# SPL Memo decoder (Carbon 2.0)

> Decode SPL Memo instructions in Rust with carbon-memo-program-decoder 2.0.0. Program ID MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr.

`carbon-memo-program-decoder` decodes the instructions of the SPL Memo program (`MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr`): 1 instruction. It decodes no accounts: `MemoProgramAccount` has no variants. It is generated with Codama from the program's IDL; see [decoders](https://carbon.sevenlabs.org/concepts/decoders.md) for how decoders plug into a pipeline.

|                  |                                                                                                                   |
| ---------------- | ----------------------------------------------------------------------------------------------------------------- |
| Crate            | [`carbon-memo-program-decoder`](https://crates.io/crates/carbon-memo-program-decoder/2.0.0) 2.0.0                 |
| Install          | `cargo add carbon-memo-program-decoder@2.0.0`                                                                     |
| Program ID       | `MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr` (`carbon_memo_program_decoder::PROGRAM_ID`)                         |
| Category         | [Core & SPL](https://carbon.sevenlabs.org/decoders/core-and-spl.md)                                               |
| Decoder          | `carbon_memo_program_decoder::MemoProgramDecoder`                                                                 |
| Instruction enum | `instructions::MemoProgramInstruction`                                                                            |
| Account enum     | `accounts::MemoProgramAccount` (no variants)                                                                      |
| Features         | `serde`, `postgres`, `graphql` (none enabled by default)                                                          |
| API docs         | [docs.rs/carbon-memo-program-decoder/2.0.0](https://docs.rs/carbon-memo-program-decoder/2.0.0)                    |
| Source           | [decoders/memo-program-decoder](https://github.com/sevenlabs-hq/carbon/tree/v2.0.0/decoders/memo-program-decoder) |

Other core and SPL decoders: [Address Lookup Table](https://carbon.sevenlabs.org/decoders/address-lookup-table.md), [Associated Token Account](https://carbon.sevenlabs.org/decoders/associated-token-account.md), [SPL Name Service](https://carbon.sevenlabs.org/decoders/name-service.md), [SPL Token](https://carbon.sevenlabs.org/decoders/token-program.md), [Stake Program](https://carbon.sevenlabs.org/decoders/stake-program.md), [System Program](https://carbon.sevenlabs.org/decoders/system-program.md), [Token-2022](https://carbon.sevenlabs.org/decoders/token-2022.md). To decode several in one pipeline, see [core and SPL program decoders](https://carbon.sevenlabs.org/decoders/core-and-spl.md).

The `serde` feature derives `Serialize`/`Deserialize` on every type, `postgres` adds tables and processors for [Postgres](https://carbon.sevenlabs.org/guides/postgres.md), and `graphql` adds a schema for the [GraphQL server](https://carbon.sevenlabs.org/guides/graphql.md).

## Usage

This program crawls recent SPL Memo transactions from the public RPC and prints every decoded `AddMemo` instruction. Add the dependencies:

```sh
cargo add carbon-core@2.0.0 carbon-memo-program-decoder@2.0.0 carbon-rpc-transaction-crawler-datasource@2.0.0 carbon-log-metrics@2.0.0 env_logger tokio --features tokio/full
```

`src/main.rs`:

```rust
use {
    carbon_core::{
        error::CarbonResult, instruction::InstructionProcessorInputType, pipeline::Pipeline,
        processor::Processor,
    },
    carbon_log_metrics::LogMetrics,
    carbon_memo_program_decoder::{
        instructions::MemoProgramInstruction, MemoProgramDecoder, PROGRAM_ID,
    },
    carbon_rpc_transaction_crawler_datasource::{ConnectionConfig, Filters, RpcTransactionCrawler},
    std::sync::Arc,
};

#[tokio::main]
async fn main() -> CarbonResult<()> {
    env_logger::init();

    // Fetches the program's recent transactions over JSON-RPC, newest first.
    let datasource = RpcTransactionCrawler::new(
        "https://api.mainnet-beta.solana.com".to_string(),
        PROGRAM_ID,
        ConnectionConfig::default(),
        Filters::new(None, None, None),
        None,
    );

    Pipeline::builder()
        .datasource(datasource)
        .metrics(Arc::new(LogMetrics::new()))
        .instruction(MemoProgramDecoder, InstructionLogger)
        .build()?
        .run()
        .await
}

struct InstructionLogger;

impl Processor<InstructionProcessorInputType<'_, MemoProgramInstruction>> for InstructionLogger {
    async fn process(
        &mut self,
        input: &InstructionProcessorInputType<'_, MemoProgramInstruction>,
    ) -> CarbonResult<()> {
        let signature = input.metadata.transaction_metadata.signature;
        let MemoProgramInstruction::AddMemo { data, .. } = input.decoded_instruction;
        println!("add_memo {signature}: {}", String::from_utf8_lossy(&data.memo));
        Ok(())
    }
}
```

```sh
RUST_LOG=info cargo run
```

Each `AddMemo` instruction prints one line with the transaction signature and the decoded `AddMemo` data. The public endpoint rate-limits requests, so the first lines can take a while; use your own RPC URL for anything beyond a test. See [stream with RPC](https://carbon.sevenlabs.org/guides/stream-with-rpc.md) for the crawler options.

## Instructions

Variants of `MemoProgramInstruction`. Each is `MemoProgramInstruction::<Variant> { program_id, data, accounts }`, where `data` and `accounts` are the types listed under the variant, exported from `carbon_memo_program_decoder::instructions`. Discriminators are the leading bytes of the instruction data, in hex.

**How an instruction decodes.** The decoder returns a variant only when all of these hold; otherwise the instruction is skipped and no processor is called:

1. The instruction's program ID is `MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr`.
2. The data starts with the variant's discriminator, and the rest deserializes into its data type.
3. The instruction has at least as many accounts as the variant requires (the "Required accounts" count under each variant).

**Accounts.** They are matched by position, in the order listed. An account marked _optional_ is `None` only when the instruction ends before it; Anchor programs pass the program ID as a placeholder for an omitted optional account, so check for `Some(PROGRAM_ID)` too. Accounts after the listed ones are in `accounts.remaining` as `AccountMeta`s. The decoder doesn't record whether an account signed or was writable: read that from `input.raw_instruction.accounts[i].is_signer` and `.is_writable`, which follow the same order. It doesn't check signer, writable, owner or PDA constraints either; the program enforced those when the transaction executed, so a decoded instruction from a successful transaction already satisfied them.

### `AddMemo`

No discriminator (the whole instruction data is the payload) · data `AddMemo` · accounts `AddMemoInstructionAccounts`.

| Field  | Type      |
| ------ | --------- |
| `memo` | `Vec<u8>` |

No named accounts.

---

Carbon 2.0.0 documentation · Web: https://carbon.sevenlabs.org/decoders/memo-program · Last updated 2026-11-09 · Index of all pages: https://carbon.sevenlabs.org/llms.txt
