SPL Memo decoder

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

On this page

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 for how decoders plug into a pipeline.

Cratecarbon-memo-program-decoder 2.0.0
Installcargo add carbon-memo-program-decoder@2.0.0
Program IDMemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr (carbon_memo_program_decoder::PROGRAM_ID)
CategoryCore & SPL
Decodercarbon_memo_program_decoder::MemoProgramDecoder
Instruction enuminstructions::MemoProgramInstruction
Account enumaccounts::MemoProgramAccount (no variants)
Featuresserde, postgres, graphql (none enabled by default)
API docsdocs.rs/carbon-memo-program-decoder/2.0.0
Sourcedecoders/memo-program-decoder

Other core and SPL decoders: Address Lookup Table, Associated Token Account, SPL Name Service, SPL Token, Stake Program, System Program, Token-2022. To decode several in one pipeline, see core and SPL program decoders.

The serde feature derives Serialize/Deserialize on every type, postgres adds tables and processors for Postgres, and graphql adds a schema for the GraphQL server.

Usage#

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

Terminal
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
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(())
    }
}
Terminal
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 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 AccountMetas. 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.

FieldType
memoVec<u8>

No named accounts.

Generated from the crate’s source at Carbon v2.0.0, so it always matches the published code. Spotted a problem? Report it; edits to this page itself are overwritten on the next release.

Your endpoints

Code samples use these instead of the placeholders, so you can copy and run them as they are. They’re stored only in this browser and never sent anywhere.