Transaction messages
Transaction messages are the canonical, signable form of a Solana transaction. They turn a fee payer, recent blockhash, and ordered instructions into one account list, one access header, and indexed program calls. Transactions sign the serialized message bytes, then carry the signatures beside those bytes for submission.
Message model
Message data
A message records the data that the Solana runtime needs to execute a transaction. It contains the recent blockhash, the accounts used by the instructions, rules for which accounts must sign or may be written, and the instruction order.
The message does not store account objects inside each instruction. Instead, each compiled instruction points to accounts and its program by index. This shared account list makes the execution data stable and gives signing one exact byte sequence to cover. The common message types and shared data shapes are exposed from packages/…/index.ts.
References: packages/…/index.ts• L3-48 packages/…/versioned.ts• L11-42
Instruction inputs
The input form is a TransactionInstruction. Each instruction names a program, supplies program data, and describes each account with AccountMeta. Account metadata states whether an account must sign and whether the program may write it. The compiler uses these declarations across all instructions rather than treating each instruction in isolation.
TransactionMessage provides the focused input model for message compilation. It keeps the payer, instruction list, and recent blockhash together so the same logical transaction can be compiled into a legacy or versioned message.
References: src/…/legacy.ts• L41-59 src/…/legacy.ts• L85-110 src/…/message.ts• L10-33
Account metadata
The compiler merges repeated account declarations by public key. If any instruction requires an account to sign or write, the combined account record keeps that stronger requirement. Program accounts are included as read-only non-signers because they are invoked rather than changed by the instruction.
The resulting account list places the fee payer first. It then groups accounts by signer and writable status. The message header describes those groups with counts, so the account order and header together determine signer positions and write access.
References: packages/…/compiled-keys.ts• L25-57 packages/…/compiled-keys.ts• L60-103
Compiled instructions
After the account list is fixed, each instruction becomes a compact record. The record keeps the program data and replaces public keys with indexes into the message account list. The message therefore preserves instruction order and account order without repeating full public keys.
This indexed form is the boundary between user-facing instruction data and the wire message. It is also the form that the runtime and the signing path use after compilation.
References: packages/…/account-keys.ts• L44-77 packages/…/index.ts• L35-48
Message forms
Message compilation variants
Message compilation supports a legacy form and versioned forms. The compiler uses the same payer, blockhash, instruction, and account rules for the shared input model, then applies the selected message format. The message compilation and versions guide explains the legacy and versioned compilation paths.
References: src/…/message.ts• L122-139 packages/…/index.ts• L10-48
Versioned message
VersionedMessage is the common view over legacy and versioned messages. Its deserializer reads the first byte to distinguish an unversioned legacy message from a versioned message, then routes supported versions to their message models. It rejects versions that the library does not support.
Version 1 messages use a static account list and carry resource limits and fee prioritization as message-level configuration. They do not use address lookup tables. Use the message compilation and versions guide for the supported forms and version selection rules. The legacy and versioned transactions guide explains how these message forms fit into their transaction wrappers.
References: packages/…/versioned.ts• L1-43 packages/…/v1.ts• L68-80
V1 message
MessageV1 is a versioned message form that keeps the canonical account and indexed-instruction model while adding message-level transaction settings. Its configuration can express resource limits and prioritization without relying on compute budget instructions. A v1 message has no address lookup table inputs and can use a larger serialized transaction size than v0.
When a v1 message is serialized, its version, configuration, account header, static accounts, lifetime token, and compiled instructions become the bytes that a transaction signs. Deserialization restores the same fields and rejects unknown configuration flags or a different message version.
References: packages/…/v1.ts• L68-80 packages/…/v1.ts• L149-175 packages/…/v1.ts• L177-226
Message lifecycle
Compilation flow
Compilation turns high-level instructions and account metadata into a message whose indexes and header can be serialized without ambiguity. The same logical input can take the legacy path or a versioned path when the selected message format supports additional account sources.
The diagram shows the shared input stage and the message-form paths.
flowchart LR
A[Payer + blockhash + instructions] --> B[Merge account metadata]
B --> C[Order account groups and build header]
C --> D[Compile program and account indexes]
D --> E[Legacy message]
D --> F[Versioned message]
F --> G[Apply version-specific settings]
G --> H[Serialize message bytes]
E --> H
H --> I[Sign message bytes]
TransactionMessage.compileToLegacyMessage() and compileToV0Message() expose the legacy and versioned output choices. MessageV1.compile() provides the v1 path with its message-level configuration. The child page Message compilation and versions explains the legacy and versioned paths in more detail.
References: src/…/message.ts• L122-139 packages/…/compiled-keys.ts• L25-103 packages/…/account-keys.ts• L44-77 packages/…/v1.ts• L124-147
Signing boundary
Signing starts only after compilation. A legacy transaction serializes its compiled message as signing data, while a VersionedTransaction serializes its VersionedMessage; each signer signs those bytes and the transaction stores the result in the signer’s message-defined slot.
Changing the payer, blockhash, instructions, account metadata, account order, or message version changes the signed message. Such a change requires signing again because the old signature no longer covers the submitted bytes. The transactions guide describes the broader transaction lifecycle.
References: src/…/legacy.ts• L600-604 src/…/legacy.ts• L723-727 src/…/versioned.ts• L43-45 src/…/versioned.ts• L94-109
Decompilation
Decompilation reverses indexed message data into a TransactionMessage. It uses the message header to recover signer and writable flags, then resolves each instruction index back to a public key and restores the program data.
For a message with additional account sources, the caller must provide the resolved loaded addresses or the matching lookup table accounts. Without that metadata the static keys are not enough to rebuild the original instructions.
References: src/…/message.ts• L35-120 packages/…/account-keys.ts• L8-42
Change checklist
When these files or sections are changed, remember to consider these:
- Changes to account grouping or key order must stay aligned with message headers, instruction indexes, and signature positions.
- Changes to lookup selection must stay aligned with lookup resolution and decompilation inputs.
- Changes to the message wire prefix, version layout, or v1 configuration mask must stay aligned with version detection, deserialization, and the bytes used for signing.
- Changes to the blockhash or payer contract must be checked at both the normalized
TransactionMessageboundary and the legacy transaction boundary.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| No recent blockhash is supplied | Message compilation stops because the message has no transaction lifetime value | Supply a recent blockhash or the nonce value used by the transaction path |
| No fee payer is supplied | The compiler cannot establish the first required writable signer | Set the payer explicitly or use the supported implicit payer behavior for a legacy transaction |
| Account metadata requires more than the supported indexed account range | Compilation cannot produce valid account indexes | Reduce the account set or choose a valid lookup-table layout |
| A message with additional account sources is decompiled without its lookup data | Loaded account keys cannot be recovered and decompilation fails | Pass matching lookup table accounts or resolved loaded addresses |
| A v1 message contains unknown configuration flags | Deserialization rejects the message instead of accepting settings it cannot interpret | Use only supported v1 transaction configuration values |
| A message changes after signing | Signature verification fails because the signature covers different bytes | Compile the final message before signing and sign again after any change |
| An unsupported message version is received | Deserialization rejects the transaction | Use a supported message version |
Key files
| File | Why to read it |
|---|---|
| src/…/message.ts | Defines the normalized payer, instruction, and blockhash input and the legacy/versioned compilation and decompilation boundary. |
| packages/…/compiled-keys.ts | Shows how account metadata becomes the ordered account groups and message header. |
| packages/…/account-keys.ts | Shows how the shared account segments become indexes in compiled instructions. |
| packages/…/index.ts | Defines the message header, lookup references, and compiled instruction data shared by message forms. |
| packages/…/versioned.ts | Defines how serialized input is identified and routed to a supported message form. |
| packages/…/v1.ts | Defines the v1 message’s static account model, message-level settings, serialization, and deserialization boundary. |
| src/…/legacy.ts | Shows how legacy transaction compilation produces the bytes that signatures cover. |
| src/…/versioned.ts | Shows how a versioned message is paired with signatures and serialized as a transaction. |