# System Program decoder (Carbon 2.0)

> Decode System Program instructions and accounts in Rust with carbon-system-program-decoder 2.0.0. Program ID 11111111111111111111111111111111.

`carbon-system-program-decoder` decodes the instructions and accounts of the System Program program (`11111111111111111111111111111111`): 13 instructions, 1 account type. 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-system-program-decoder`](https://crates.io/crates/carbon-system-program-decoder/2.0.0) 2.0.0                 |
| Install          | `cargo add carbon-system-program-decoder@2.0.0`                                                                       |
| Program ID       | `11111111111111111111111111111111` (`carbon_system_program_decoder::PROGRAM_ID`)                                      |
| Category         | [Core & SPL](https://carbon.sevenlabs.org/decoders/core-and-spl.md)                                                   |
| Decoder          | `carbon_system_program_decoder::SystemProgramDecoder`                                                                 |
| Instruction enum | `instructions::SystemProgramInstruction`                                                                              |
| Account enum     | `accounts::SystemProgramAccount`                                                                                      |
| Features         | `serde`, `postgres`, `graphql` (none enabled by default)                                                              |
| API docs         | [docs.rs/carbon-system-program-decoder/2.0.0](https://docs.rs/carbon-system-program-decoder/2.0.0)                    |
| Source           | [decoders/system-program-decoder](https://github.com/sevenlabs-hq/carbon/tree/v2.0.0/decoders/system-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 Memo](https://carbon.sevenlabs.org/decoders/memo-program.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), [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 System Program transactions from the public RPC and prints every decoded `TransferSol` instruction. Add the dependencies:

```sh
cargo add carbon-core@2.0.0 carbon-system-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_system_program_decoder::{
        instructions::SystemProgramInstruction, SystemProgramDecoder, 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(SystemProgramDecoder, InstructionLogger)
        .build()?
        .run()
        .await
}

struct InstructionLogger;

impl Processor<InstructionProcessorInputType<'_, SystemProgramInstruction>> for InstructionLogger {
    async fn process(
        &mut self,
        input: &InstructionProcessorInputType<'_, SystemProgramInstruction>,
    ) -> CarbonResult<()> {
        let signature = input.metadata.transaction_metadata.signature;
        if let SystemProgramInstruction::TransferSol { data, accounts, .. } = input.decoded_instruction {
            println!("transfer_sol {signature}: {data:?} source={}", accounts.source);
        }
        Ok(())
    }
}
```

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

Each `TransferSol` instruction prints one line with the transaction signature and the decoded `TransferSol` 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.

### Decode accounts

The transaction crawler emits transactions only. To decode accounts, use a datasource that emits account updates. This program subscribes to the program's accounts with `programSubscribe` on the public WebSocket endpoint and prints every decoded `Nonce` account as it changes. Add the datasource and the Solana RPC types it takes:

```sh
cargo add carbon-rpc-program-subscribe-datasource@2.0.0 solana-client@4.2.2
```

`src/main.rs`:

```rust
use {
    carbon_core::{
        account::AccountProcessorInputType, error::CarbonResult, pipeline::Pipeline,
        processor::Processor,
    },
    carbon_log_metrics::LogMetrics,
    carbon_system_program_decoder::{
        accounts::SystemProgramAccount, SystemProgramDecoder, PROGRAM_ID,
    },
    carbon_rpc_program_subscribe_datasource::{Filters, RpcProgramSubscribe},
    solana_client::{
        rpc_config::{RpcAccountInfoConfig, RpcProgramAccountsConfig, UiAccountEncoding},
        rpc_filter::RpcFilterType,
    },
    std::sync::Arc,
};

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

    // Streams every change to an account owned by the program (programSubscribe).
    let config = RpcProgramAccountsConfig {
        // Nonce accounts are 80 bytes; without a filter this streams every wallet.
        filters: Some(vec![RpcFilterType::DataSize(80)]),
        account_config: RpcAccountInfoConfig {
            encoding: Some(UiAccountEncoding::Base64),
            ..Default::default()
        },
        ..Default::default()
    };
    let datasource = RpcProgramSubscribe::new(
        "wss://api.mainnet-beta.solana.com".to_string(),
        Filters::new(PROGRAM_ID, Some(config)),
    );

    Pipeline::builder()
        .datasource(datasource)
        .metrics(Arc::new(LogMetrics::new()))
        .account(SystemProgramDecoder, AccountLogger)
        .build()?
        .run()
        .await
}

struct AccountLogger;

impl Processor<AccountProcessorInputType<'_, SystemProgramAccount>> for AccountLogger {
    async fn process(
        &mut self,
        input: &AccountProcessorInputType<'_, SystemProgramAccount>,
    ) -> CarbonResult<()> {
        let SystemProgramAccount::Nonce(nonce) = &input.decoded_account.data;
        println!("nonce {}: {nonce:?}", input.metadata.pubkey);
        Ok(())
    }
}
```

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

Each update to a `Nonce` account prints its address and decoded fields; the program runs until you stop it. Cargo resolves `solana-client` to 4.2.2, the exact version the datasource pins, so both use the same `RpcProgramAccountsConfig` type. To load every existing account once instead of streaming changes, see [load account state](https://carbon.sevenlabs.org/guides/load-account-state.md).

## Instructions

Variants of `SystemProgramInstruction`. Each is `SystemProgramInstruction::<Variant> { program_id, data, accounts }`, where `data` and `accounts` are the types listed under the variant, exported from `carbon_system_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 `11111111111111111111111111111111`.
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.

### `AdvanceNonceAccount`

Discriminator `04000000` · data `AdvanceNonceAccount` · accounts `AdvanceNonceAccountInstructionAccounts`.

No data fields.

Required accounts: 3; extras go to `remaining`.

Fields of `AdvanceNonceAccountInstructionAccounts`, in account order:

| #  | Field                       | Type               |
| -- | --------------------------- | ------------------ |
| 0  | `nonce_account`             | `Pubkey`           |
| 1  | `recent_blockhashes_sysvar` | `Pubkey`           |
| 2  | `nonce_authority`           | `Pubkey`           |
| 3… | `remaining`                 | `Vec<AccountMeta>` |

### `Allocate`

Discriminator `08000000` · data `Allocate` · accounts `AllocateInstructionAccounts`.

| Field   | Type  |
| ------- | ----- |
| `space` | `u64` |

Required accounts: 1; extras go to `remaining`.

Fields of `AllocateInstructionAccounts`, in account order:

| #  | Field         | Type               |
| -- | ------------- | ------------------ |
| 0  | `new_account` | `Pubkey`           |
| 1… | `remaining`   | `Vec<AccountMeta>` |

### `AllocateWithSeed`

Discriminator `09000000` · data `AllocateWithSeed` · accounts `AllocateWithSeedInstructionAccounts`.

| Field             | Type     |
| ----------------- | -------- |
| `base`            | `Pubkey` |
| `seed`            | `String` |
| `space`           | `u64`    |
| `program_address` | `Pubkey` |

Required accounts: 2; extras go to `remaining`.

Fields of `AllocateWithSeedInstructionAccounts`, in account order:

| #  | Field          | Type               |
| -- | -------------- | ------------------ |
| 0  | `new_account`  | `Pubkey`           |
| 1  | `base_account` | `Pubkey`           |
| 2… | `remaining`    | `Vec<AccountMeta>` |

### `Assign`

Discriminator `01000000` · data `Assign` · accounts `AssignInstructionAccounts`.

| Field             | Type     |
| ----------------- | -------- |
| `program_address` | `Pubkey` |

Required accounts: 1; extras go to `remaining`.

Fields of `AssignInstructionAccounts`, in account order:

| #  | Field       | Type               |
| -- | ----------- | ------------------ |
| 0  | `account`   | `Pubkey`           |
| 1… | `remaining` | `Vec<AccountMeta>` |

### `AssignWithSeed`

Discriminator `0a000000` · data `AssignWithSeed` · accounts `AssignWithSeedInstructionAccounts`.

| Field             | Type     |
| ----------------- | -------- |
| `base`            | `Pubkey` |
| `seed`            | `String` |
| `program_address` | `Pubkey` |

Required accounts: 2; extras go to `remaining`.

Fields of `AssignWithSeedInstructionAccounts`, in account order:

| #  | Field          | Type               |
| -- | -------------- | ------------------ |
| 0  | `account`      | `Pubkey`           |
| 1  | `base_account` | `Pubkey`           |
| 2… | `remaining`    | `Vec<AccountMeta>` |

### `AuthorizeNonceAccount`

Discriminator `07000000` · data `AuthorizeNonceAccount` · accounts `AuthorizeNonceAccountInstructionAccounts`.

| Field                 | Type     |
| --------------------- | -------- |
| `new_nonce_authority` | `Pubkey` |

Required accounts: 2; extras go to `remaining`.

Fields of `AuthorizeNonceAccountInstructionAccounts`, in account order:

| #  | Field             | Type               |
| -- | ----------------- | ------------------ |
| 0  | `nonce_account`   | `Pubkey`           |
| 1  | `nonce_authority` | `Pubkey`           |
| 2… | `remaining`       | `Vec<AccountMeta>` |

### `CreateAccount`

Discriminator `00000000` · data `CreateAccount` · accounts `CreateAccountInstructionAccounts`.

| Field             | Type     |
| ----------------- | -------- |
| `lamports`        | `u64`    |
| `space`           | `u64`    |
| `program_address` | `Pubkey` |

Required accounts: 2; extras go to `remaining`.

Fields of `CreateAccountInstructionAccounts`, in account order:

| #  | Field         | Type               |
| -- | ------------- | ------------------ |
| 0  | `payer`       | `Pubkey`           |
| 1  | `new_account` | `Pubkey`           |
| 2… | `remaining`   | `Vec<AccountMeta>` |

### `CreateAccountWithSeed`

Discriminator `03000000` · data `CreateAccountWithSeed` · accounts `CreateAccountWithSeedInstructionAccounts`.

| Field             | Type     |
| ----------------- | -------- |
| `base`            | `Pubkey` |
| `seed`            | `String` |
| `amount`          | `u64`    |
| `space`           | `u64`    |
| `program_address` | `Pubkey` |

Required accounts: 2 (3 listed); extras go to `remaining`.

Fields of `CreateAccountWithSeedInstructionAccounts`, in account order:

| #  | Field          | Type               |
| -- | -------------- | ------------------ |
| 0  | `payer`        | `Pubkey`           |
| 1  | `new_account`  | `Pubkey`           |
| 2  | `base_account` | `Option<Pubkey>`   |
| 3… | `remaining`    | `Vec<AccountMeta>` |

### `InitializeNonceAccount`

Discriminator `06000000` · data `InitializeNonceAccount` · accounts `InitializeNonceAccountInstructionAccounts`.

| Field             | Type     |
| ----------------- | -------- |
| `nonce_authority` | `Pubkey` |

Required accounts: 3; extras go to `remaining`.

Fields of `InitializeNonceAccountInstructionAccounts`, in account order:

| #  | Field                       | Type               |
| -- | --------------------------- | ------------------ |
| 0  | `nonce_account`             | `Pubkey`           |
| 1  | `recent_blockhashes_sysvar` | `Pubkey`           |
| 2  | `rent_sysvar`               | `Pubkey`           |
| 3… | `remaining`                 | `Vec<AccountMeta>` |

### `TransferSol`

Discriminator `02000000` · data `TransferSol` · accounts `TransferSolInstructionAccounts`.

| Field    | Type  |
| -------- | ----- |
| `amount` | `u64` |

Required accounts: 2; extras go to `remaining`.

Fields of `TransferSolInstructionAccounts`, in account order:

| #  | Field         | Type               |
| -- | ------------- | ------------------ |
| 0  | `source`      | `Pubkey`           |
| 1  | `destination` | `Pubkey`           |
| 2… | `remaining`   | `Vec<AccountMeta>` |

### `TransferSolWithSeed`

Discriminator `0b000000` · data `TransferSolWithSeed` · accounts `TransferSolWithSeedInstructionAccounts`.

| Field        | Type     |
| ------------ | -------- |
| `amount`     | `u64`    |
| `from_seed`  | `String` |
| `from_owner` | `Pubkey` |

Required accounts: 3; extras go to `remaining`.

Fields of `TransferSolWithSeedInstructionAccounts`, in account order:

| #  | Field          | Type               |
| -- | -------------- | ------------------ |
| 0  | `source`       | `Pubkey`           |
| 1  | `base_account` | `Pubkey`           |
| 2  | `destination`  | `Pubkey`           |
| 3… | `remaining`    | `Vec<AccountMeta>` |

### `UpgradeNonceAccount`

Discriminator `0c000000` · data `UpgradeNonceAccount` · accounts `UpgradeNonceAccountInstructionAccounts`.

No data fields.

Required accounts: 1; extras go to `remaining`.

Fields of `UpgradeNonceAccountInstructionAccounts`, in account order:

| #  | Field           | Type               |
| -- | --------------- | ------------------ |
| 0  | `nonce_account` | `Pubkey`           |
| 1… | `remaining`     | `Vec<AccountMeta>` |

### `WithdrawNonceAccount`

Discriminator `05000000` · data `WithdrawNonceAccount` · accounts `WithdrawNonceAccountInstructionAccounts`.

| Field             | Type  |
| ----------------- | ----- |
| `withdraw_amount` | `u64` |

Required accounts: 5; extras go to `remaining`.

Fields of `WithdrawNonceAccountInstructionAccounts`, in account order:

| #  | Field                       | Type               |
| -- | --------------------------- | ------------------ |
| 0  | `nonce_account`             | `Pubkey`           |
| 1  | `recipient_account`         | `Pubkey`           |
| 2  | `recent_blockhashes_sysvar` | `Pubkey`           |
| 3  | `rent_sysvar`               | `Pubkey`           |
| 4  | `nonce_authority`           | `Pubkey`           |
| 5… | `remaining`                 | `Vec<AccountMeta>` |

## Accounts

Variants of `SystemProgramAccount`. Each wraps a boxed struct from `carbon_system_program_decoder::accounts::<module>`. `decode_account` only considers accounts owned by `PROGRAM_ID` and returns the first variant that matches.

### `Nonce`

No discriminator (matched by Borsh layout) · `accounts::nonce::Nonce`.

| Field                    | Type                            |
| ------------------------ | ------------------------------- |
| `version`                | [`NonceVersion`](#nonceversion) |
| `state`                  | [`NonceState`](#noncestate)     |
| `authority`              | `Pubkey`                        |
| `blockhash`              | `Pubkey`                        |
| `lamports_per_signature` | `u64`                           |

## Types

Types used by the instructions, accounts and events above, exported from `carbon_system_program_decoder::types`.

### `NonceState`

Enum `types::NonceState`.

| Variant         |
| --------------- |
| `Uninitialized` |
| `Initialized`   |

### `NonceVersion`

Enum `types::NonceVersion`.

| Variant   |
| --------- |
| `Legacy`  |
| `Current` |

---

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