Instructions and message construction
Instructions describe a program call as a target program, an ordered set of account roles, and program input bytes. Message construction turns those instructions into the account-key table, signer and write permissions, instruction indexes, recent block hash, and optional address-table or inline transaction settings that a transaction can sign and send. This page is a companion to Core data model, and relates to Keys and encoding and Transaction lifecycle.
Instruction model
An Instruction is the common contract for a program call. It supplies the program identifier, the accounts that the program must receive, and the encoded data for the call. A GenericInstruction provides this contract when the caller already has the account metadata and raw data; program packages provide richer instruction values that encode their own data and account layout. References: transaction.go• L126-158, generic_instruction.go• L17-49
Account metadata
AccountMeta describes how one public key participates in an instruction. IsSigner marks a key that must approve the transaction, while IsWritable marks a key whose on-chain state may change. The same key can appear in more than one instruction; message construction combines those uses so that a writable use is not lost. References: account.go• L57-104, transaction.go• L291-343
Instruction account lists preserve the order required by the target program. The message later replaces each account with an index into its shared key list, while the instruction-specific account order remains the order passed to the program. References: transaction.go• L499-515, transaction.go• L126-139
Message construction
Message construction compiles a group of instructions into one transaction-ready execution plan. It selects a fee payer, gathers and de-duplicates program and account keys, groups keys by signer and write status, and records each instruction as indexes into the resulting key space. References: transaction.go• L235-258, transaction.go• L291-387, transaction.go• L476-519
The fee payer is the first key in the message and is always a writable signer. Callers can set it explicitly; otherwise construction uses the first signer in the first instruction. A transaction needs at least one instruction and must have a usable payer. References: transaction.go• L214-227, transaction.go• L235-258, transaction.go• L348-386
Message header
The message header summarizes the permission layout of the static key list. It records the number of required signatures plus the counts of read-only signed and unsigned keys. These counts let readers derive signer and writable status from key position without repeating metadata in every instruction. References: message.go• L1150-1164, transaction.go• L424-437
Compiled account views
A compiled message provides views that map instruction indexes back to programs and accounts. These views expose signers, writable accounts, invoked program identifiers, and instruction-specific signers while keeping the shared key table as the source of truth. References: message.go• L854-910, message.go• L913-1148
Address table lookups
Version 0 messages can keep some non-signer accounts in address lookup tables instead of listing every public key in the static key list. A lookup names a table account and separates the selected entries into writable and read-only indexes. The compiled instruction index space places static keys first, then writable looked-up keys, then read-only looked-up keys. References: message.go• L46-84, message.go• L441-495, transaction.go• L407-489
The table contents are external state. A decoded versioned message is therefore not ready for full account inspection until the caller supplies the table contents. Resolution expands the lookup entries into the complete key list and keeps the order used by instruction indexes. References: message.go• L32-44, message.go• L546-657, message_v0_test.go• L19-49
The construction path can accept table contents and create the lookup descriptors at the same time. It does not place fee-payer, signer, or invoked program keys in lookups, so those keys remain available in the static portion of the message. References: transaction.go• L160-180, transaction.go• L260-289, transaction.go• L407-474
Message serialization
Binary serialization produces the bytes that signatures cover and that the network consumes. Legacy messages write the header, all account keys, recent block hash, and compiled instructions. Version 0 messages add a version prefix and serialize static keys plus lookup descriptors. Version 1 messages use a version prefix and can carry an inline transaction configuration instead of address-table lookups. References: message.go• L386-496, message_v1.go• L191-271
Message versions
A Message supports three wire formats. The format controls how the message identifies itself and which extra account or transaction settings it can carry.
| Format | Additional message state | Address lookup support |
|---|---|---|
| Legacy | None | No |
| Version 0 | Address-table lookup descriptors | Yes |
| Version 1 | Inline transaction configuration | No |
Legacy messages use the first header byte directly. Versioned messages set the high bit and use the remaining bits to identify the format. Version 1 is not silently changed to another format when it has version 1-only state. References: message.go• L98-108, message.go• L161-201, message_v1.go• L33-50
Inline transaction configuration
Version 1 messages can carry transaction-level limits and fee settings in the message itself. The optional TransactionConfig covers the total priority fee, compute-unit limit, loaded-account data limit, and requested heap size; unset values are not requested. References: message_v1.go• L58-69, message_v1.go• L71-120
The configuration has a mask that states which values are present. Version 1 serialization writes the selected values in the defined order, while decoding rejects unknown or incomplete mask bits. This keeps the signed bytes and the runtime settings aligned. References: message_v1.go• L123-188, message_v1.go• L203-271, message_v1.go• L274-363
Message decoding identifies the format from the first byte. A legacy message uses that byte as its first header value; a versioned message sets the high bit and carries the version in the remaining bits. JSON uses addressTableLookups to preserve version 0 and transactionConfig to preserve version 1 because the private version field has no JSON field. These two version-specific forms cannot carry conflicting non-empty state. References: message.go• L223-312, message.go• L511-535, message_v1.go• L274-284
Transaction serialization places the compact signature count and signature bytes before the serialized message. If the message requires more signatures than the transaction currently holds, serialization adds zero signatures so the byte layout still matches the message contract. Signature verification signs and checks the exact serialized message bytes. References: transaction.go• L34-43, transaction.go• L524-548, transaction.go• L736-760
Instruction decoding
Compiled instructions can be mapped back to typed program instructions when a decoder is registered for the program identifier. The decoder receives only the account metadata selected by that instruction, not the whole message account list. Unknown program identifiers remain valid compiled instructions but cannot be turned into a registered typed value. References: transaction.go• L141-152, registry.go• L27-32, registry.go• L112-117
The program packages register decoders against their program identifiers. Their typed instruction values use the shared instruction contract, expose account metadata, and encode program data for message construction. References: programs/…/instructions.go• L32-43, programs/…/instructions.go• L121-165, programs/…/instructions.go• L28-36, programs/…/instructions.go• L39-73
Program identifiers
Program identifiers are public keys that name the on-chain programs invoked by instructions. The root package provides canonical identifiers for core runtime programs and common token or utility programs, while program packages expose the identifier they use for instruction creation and decoder registration. References: program_ids.go• L17-48, program_ids.go• L50-88, programs/…/instructions.go• L32-42, programs/…/instructions.go• L28-36
The identifiers cover several roles in the wider system:
| Group | Purpose represented by the identifiers |
|---|---|
| Core runtime | Account creation, configuration, staking, voting, program loading, feature control, and proof or signature checks |
| Transaction support | Compute budget control and address lookup table management |
| Token and asset use | Fungible and non-fungible token programs, token swaps, lending, associated token accounts, metadata, and well-known token addresses |
| Transaction records | Current and legacy memo programs |
The file also keeps the deprecated memo identifier so older transactions can still be recognized. SolMint and WrappedSol are token-related addresses rather than executable program identifiers. References: program_ids.go• L17-47, program_ids.go• L50-88
The identifier becomes an ordinary read-only, non-signer entry in the message key table. Each compiled instruction stores its program as ProgramIDIndex, so resolving the program means looking up that index in the message keys. References: transaction.go• L295-313, transaction.go• L499-515, message.go• L913-926
Sysvar identifiers
Sysvars are read-only on-chain accounts that expose runtime data to programs and clients. The root package defines their public keys, and the sysvar package re-exports the keys next to matching data types and decoders. References: sysvar.go• L17-77, sysvar/ids.go• L19-40
The identifiers most relevant to instruction account lists represent cluster time, epoch rules, rent, slot history, stake history, epoch rewards, and restart state. The Instructions sysvar also identifies the account that exposes the serialized instructions of the message while the runtime processes it. References: sysvar.go• L24-73
Sysvar data gives callers a typed view of runtime state after account data is fetched. For example, Clock represents the current slot, epoch, and estimated Unix time, while EpochSchedule represents epoch length and warmup rules. These values support program and client decisions without changing the message model. References: sysvar/clock.go• L23-60, sysvar/epoch_schedule.go• L23-48, sysvar/rent.go• L25-61
Construction flow
The following flow shows how typed or generic instructions become a message and then serialized transaction bytes.
flowchart LR
I[Instructions] --> M[Account metadata and program IDs]
M --> K[Shared key table]
K --> H[Header and permissions]
I --> C[Compiled instruction indexes and data]
H --> X[Message]
C --> X
X --> S[Serialized message]
S --> T[Signatures plus transaction bytes]
The same message is the link between human-readable instruction intent and the bytes used for signing. Address lookup data adds an external resolution step only when a version 0 message refers to accounts indirectly. Version 1 settings stay inside the signed message instead of using address lookups. References: transaction.go• L235-258, transaction.go• L291-519, message.go• L386-496, message_v1.go• L203-271, transaction.go• L524-548
Change checklist
When these files or sections are changed, remember to consider these:
- Changes to
AccountMetaflags must keep message header counts and compiled account indexes consistent. - Changes to key ordering or de-duplication must be checked against fee-payer placement, signer order, and address lookup index order.
- Changes to message version detection or wire layout must preserve legacy, version 0, and version 1 round trips and signature coverage.
- Changes to version 1 transaction settings must keep the config mask, value order, JSON form, and version-selection rules aligned.
- Changes to a program identifier must update the instruction package's active identifier and decoder registration together.
- Changes to sysvar identifiers must keep root constants,
sysvarre-exports, and the matching typed data model aligned. - Changes to address lookup use must preserve the requirement to provide table contents before resolving account metadata.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| No instruction is supplied | A transaction cannot be built | NewTransaction rejects an empty instruction list |
| No fee payer is set and the first instruction has no signer | Message construction cannot choose the required first signer | Set a payer explicitly or include a signer in the first instruction |
| A versioned message has lookups but no table contents | Full account and permission queries return ErrAddressTablesNotSet | Fetch each table and call SetAddressTables before resolution |
| A lookup index is outside its table | Account resolution fails instead of producing a wrong key | Validate table contents and index ranges |
| A compiled program index is outside the message key list | Program resolution fails | Preserve the shared key table and instruction indexes as one contract |
| A program identifier has no registered decoder | Typed instruction decoding returns ErrInstructionDecoderNotFound | Register the decoder for the exact program identifier |
| A version 1 message contains address-table lookups or is forced to legacy or version 0 with inline config | Serialization or version selection fails rather than dropping version-specific state | Keep version 1 configuration and address lookups separate |
| A version 1 config mask has unknown or partial priority-fee bits | Message decoding rejects the configuration | Use the supported TransactionConfig fields and preserve the complete mask |
| A version 1 message exceeds its address, instruction, signature, or wire-size limits | Sanitization or serialization rejects the message | Sanitize version 1 messages before signing |
| Message bytes are changed after signing | Signature verification fails | Sign and verify the exact serialized message |
Key files
| File | Why to read it |
|---|---|
| transaction.go | Shows the instruction contract, transaction builder, message compilation, and transaction serialization boundary. |
| message.go | Defines message versions, headers, compiled instructions, address lookup handling, account views, and binary or JSON serialization. |
| message_v1.go | Defines version 1 inline transaction settings, limits, validation, and wire encoding. |
| account.go | Defines account metadata and the signer or writable flags used during compilation. |
| generic_instruction.go | Shows the smallest instruction representation for callers that already have program data bytes. |
| registry.go | Explains how compiled program calls can become typed instructions through program-specific decoders. |
| program_ids.go | Lists the canonical core, token, utility, memo, and token-related addresses consumed by instructions. |
| sysvar.go | Defines the canonical runtime account identifiers, including the Instructions sysvar. |
| sysvar/ids.go | Connects sysvar identifiers to the typed sysvar package. |
| programs/…/instructions.go | Illustrates a typed instruction family with a program identifier and encoded variant data. |
| programs/…/instructions.go | Illustrates a compact typed instruction family and decoder registration. |