You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Instruction introspection is a powerful capability on Solana that allows a program to analyze other instructions
8
-
within the same transaction, including those not yet executed. This enables you to dynamically respond to or augment
9
-
these instructions — for example, by injecting safeguards, validating behavior, or integrating instructions from
10
-
external programs into your own logic.
7
+
Instruction introspection is a powerful capability on Solana that allows a program to analyze other instructions within the same transaction, including those not yet executed. This enables you to dynamically respond to or augment these instructions — for example, by injecting safeguards, validating behavior, or integrating instructions from external programs into your own logic.
11
8
12
9
This is made possible by a special system account called the `Instructions` sysvar. Sysvars are read-only accounts maintained by the Solana runtime that expose internal state to programs (e.g., clock, rent, epoch schedule, etc.). The Instructions sysvar specifically exposes the full list of instructions in the current transaction, along with their metadata and serialized data.
13
10
14
-
Here’s how Solana serializes this information at runtime:
11
+
Here's how Solana serializes this information at runtime:
This means that by reading the `Instructions` sysvar account inside your program, you can access all the instructions included in the current transaction.
65
62
66
-
You don’t need to parse the raw bytes manually. Solana provides helper functions:
63
+
You don't need to parse the raw bytes manually. Solana provides helper functions:
67
64
-`load_current_index_checked`: returns the index of the currently executing instruction.
68
65
-`load_instruction_at_checked`: lets you load a specific instruction by its index in a parsed, deserialized format.
69
66
@@ -101,7 +98,6 @@ When using instruction introspection, it’s essential to enforce strict constra
101
98
102
99
By applying these constraints, you ensure that your program is responding only to valid and trusted instructions, making your logic more robust, composable, and secure.
103
100
104
-
Together with transaction atomicity, these checks allow you to build robust, composable logic that can safely interact
105
-
with other programs and instructions within the same transaction.
101
+
Together with transaction atomicity, these checks allow you to build robust, composable logic that can safely interact with other programs and instructions within the same transaction.
106
102
107
103
> Remember, transactions in Solana are atomic. If any instruction fails, the entire transaction is rolled back.
0 commit comments