---
title: Instruction Introspection
description:
  How Solana programs inspect other instructions in the same transaction using
  the Instructions sysvar. Load instructions by absolute index or relative
  offset. CPI inner instructions are not accessible.
url: /docs/core/instructions/instruction-introspection
type: reference
prerequisites:
  - /docs/core/instructions
  - /docs/core/instructions/instruction-structure
related:
  - /docs/core/transactions/transaction-structure
  - /docs/core/cpi
---

<Callout type="info" title="Summary">
  The Instructions sysvar (`Sysvar1nstructions1111111111111111111111111`) lets a
  program read all top-level instructions in the current transaction by index or
  relative offset. CPI inner instructions are not accessible.
</Callout>

## Instructions sysvar

Programs can inspect all top-level instructions in the current transaction via
the **Instructions sysvar** (`Sysvar1nstructions1111111111111111111111111`).
This lets a program inspect the other instructions in the same transaction, for
example to verify that a specific instruction is in the same transaction as the
instruction it's executing.

<Callout type="info">
  The Instructions sysvar only contains top-level instructions from the
  transaction message. Inner instructions invoked via CPI are not accessible
  through this sysvar.
</Callout>

The instructions sysvar is not accessed through the normal _rs`Sysvar`_ trait.
Instead, it is accessed through free functions in the
[`solana_instructions_sysvar`](https://github.com/anza-xyz/solana-sdk/blob/clock%40v2.2.3/instructions-sysvar/src/lib.rs#L1)
crate.

The sysvar data is serialized with a custom binary layout:

| Offset       | Size   | Description                                    |
| ------------ | ------ | ---------------------------------------------- |
| 0            | 2      | `num_instructions` (u16, little-endian)        |
| 2            | 2 \* N | Byte offsets for each instruction (u16 each)   |
| varies       | varies | Serialized instruction data                    |
| last 2 bytes | 2      | Current instruction index (u16, little-endian) |

Each serialized instruction contains: the number of accounts (u16), the accounts
as 33-byte entries (1 flag byte + 32-byte pubkey), the program ID (32 bytes),
the data length (u16), and the raw data bytes.

Key functions:

- [`load_current_index_checked(account_info)`](https://github.com/anza-xyz/solana-sdk/blob/clock%40v2.2.3/instructions-sysvar/src/lib.rs#L151):
  Returns the index of the currently executing instruction. The runtime
  [updates](https://github.com/anza-xyz/agave/blob/v3.1.8/transaction-context/src/lib.rs#L356-L359)
  this value each time a new top-level instruction begins.
- [`load_instruction_at_checked(index, account_info)`](https://github.com/anza-xyz/solana-sdk/blob/clock%40v2.2.3/instructions-sysvar/src/lib.rs#L246):
  Deserializes the instruction at the given absolute index.
- [`get_instruction_relative(offset, account_info)`](https://github.com/anza-xyz/solana-sdk/blob/clock%40v2.2.3/instructions-sysvar/src/lib.rs#L267):
  Loads an instruction relative to the current one (e.g., `-1` for the previous
  instruction, `1` for the next).
