Introducing a new way to review your PRs.

Read the announcement

solana-foundation / solana-web3.js

Solana JavaScript SDK

View on GitHub

23 documents · Updated Nov 16, 2026

docs / legacy-and-versioned-transactions

Legacy and versioned transactions

Transactions turn program instructions into signed data that a Solana cluster can execute as one atomic unit. This page explains the two transaction models, how they choose a payer and collect signatures, how they compile messages, and where legacy and versioned transactions cannot be used interchangeably. See Transactions for the wider transaction life cycle, Messages for message concepts, Message compilation and versions for message selection, and Transaction send and confirm for submission and confirmation.

Transaction models

The library supports a legacy transaction model and a versioned transaction model. Both carry a message and signatures, but they differ in when the message is built and how account addresses are represented.

Legacy transactions

Transaction is the flexible model for the original transaction format. It accepts instructions, a recent blockhash or a durable nonce, a fee payer, and optional signature records. Its message keeps all account addresses in one static list.

The legacy model also supports older workflows that populate a transaction from an existing message or add an externally created signature. It is the compatibility choice when the caller or downstream system expects the legacy wire format.

References: src/…/legacy.ts• L137-190 src/…/legacy.ts• L210-323 src/…/legacy.ts• L901-969

Versioned transactions

VersionedTransaction wraps a versioned message and a fixed set of signature slots. The message carries the payer, required signer order, account model, and transaction data before the transaction object is created.

The versioned model starts from a compiled message. It does not accept a list of uncompiled instructions or manage a fee payer property itself. The payer and signer order are already part of the message when the versioned transaction is created.

References: src/…/versioned.ts• L13-41 src/…/versioned.ts• L43-121 src/…/versioned.ts• L5-35

Transaction messages

TransactionMessage is the shared instruction-level input used to choose a message format. It holds one payer, one recent blockhash, and an ordered list of instructions. The caller can compile that same input into a legacy message or a versioned message.

This separation keeps instruction construction independent from the final transaction format. After compilation, the resulting message is the source of truth for account order, required signers, instruction indexes, and the bytes that signers cover.

References: src/…/message.ts• L10-33 src/…/message.ts• L122-139 src/…/index.ts• L9-46

Construction and compilation

Construction starts with instructions and transaction lifetime data. Compilation resolves those inputs into a message that has a payer, account metadata, signer counts, and indexed instructions.

Instruction inputs

An instruction names a program and the accounts that program uses. Each account has a public key plus two roles: whether it must sign and whether the program may write to it. A transaction may add individual instructions or merge the instructions from another legacy transaction.

Legacy construction can use a recent blockhash with its last valid block height. It can instead use durable nonce information. In that case, compilation uses the nonce value and places the nonce-advance instruction first unless the caller already placed it first.

References: src/…/legacy.ts• L41-59 src/…/legacy.ts• L156-190 src/…/legacy.ts• L345-369 src/…/legacy.ts• L382-400

Legacy message compilation

Legacy compilation gathers every instruction account and program account into one account set. It merges repeated accounts so that the strongest signer and writable roles remain. It then places the payer first and builds the message header and instruction indexes.

The result is a legacy message. It contains the account list, the recent blockhash selected for the transaction, and instructions that refer to accounts by index. The message is the data signed by every required signer.

References: src/…/legacy.ts• L403-570

Versioned message compilation

Versioned compilation begins with the same payer, instructions, and recent blockhash. It tracks each account as a signer, writable account, or invoked program. This shared key view lets the compiler build the message header and choose which non-signer accounts can move to an address lookup table.

Address lookup selection removes matching non-signer accounts from the static set and records their lookup-table indexes. The compiled instructions still use one account index space after static and looked-up accounts are combined.

The following flow shows how one instruction set can produce either message form and then become a signed transaction.

flowchart LR
  I[Instructions] --> B[TransactionMessage]
  B --> L[Legacy message]
  B --> V[Versioned message]
  L --> LT[Transaction]
  V --> VT[VersionedTransaction]
  LT --> LS[Legacy wire bytes]
  VT --> VS[Versioned wire bytes]

References: src/…/message.ts• L122-139 packages/…/compiled-keys.ts• L8-104 packages/…/compiled-keys.ts• L106-163

Payer and signature management

The payer and the signer set define who authorizes the message and who pays its fee. The two transaction models expose this state at different stages, so callers must set it before signing and must not change signed message data afterward.

Fee payer selection

For a legacy transaction, feePayer is normally set in the constructor or as a property. If it is absent, the first known signer can become the implicit payer during message compilation. Compilation always promotes the payer to the first account and marks it as a writable signer.

For a versioned transaction, the payer is selected when TransactionMessage compiles the message. The first required signer in the compiled message is the payer by message convention. Changing the payer therefore means building a new message and signing it again.

References: src/…/legacy.ts• L403-411 src/…/legacy.ts• L484-499 src/…/message.ts• L24-33 packages/…/compiled-keys.ts• L44-57 packages/…/compiled-keys.ts• L64-94

Legacy signature records

Legacy transactions keep a public key beside each signature. A signature may be missing while a transaction moves between signers. sign replaces the signer set and signs all given signers. partialSign keeps the current set and fills only the supplied signer slots. addSignature accepts a signature made outside the library.

The transaction compiles its message before it signs. It orders signature slots to match the required signer accounts in the message. Full verification rejects missing or invalid signatures by default. Serialization can allow missing signatures when a caller explicitly disables the all-signatures requirement.

References: src/…/legacy.ts• L576-597 src/…/legacy.ts• L647-758 src/…/legacy.ts• L760-832

Versioned signature slots

Versioned transactions allocate one 64-byte slot for each required signature in the message. The sign method finds each signer in the message's required signer prefix and writes the signature at that index. addSignature performs the same lookup for an externally made signature and requires a 64-byte value.

The versioned API does not expose the legacy nullable signature records or its legacy signature verification options. A caller must supply the required signatures before sending. The signed bytes are the serialized versioned message, so any message change requires new signatures.

References: src/…/versioned.ts• L18-41 src/…/versioned.ts• L124-156

Serialization and deserialization

Serialization joins the signature area with the serialized message to create wire data. Deserialization first separates the signature area, then selects a message reader from the message prefix.

Wire serialization

Legacy serialization signs and serializes the compiled legacy message. It checks signatures by default and fails when a required signature is missing or invalid. Its signature area uses a zero-filled value for an unfilled slot when the caller permits partial serialization.

Versioned serialization writes the number of signature slots, all signature bytes, and the serialized versioned message. The message carries the version marker. This marker lets readers distinguish versioned data from the legacy format without relying on a separate transaction type field.

References: src/…/legacy.ts• L797-864 src/…/versioned.ts• L43-77

Message reconstruction

Transaction.from reads legacy wire data only. It parses the signature records and legacy message, then rebuilds instructions from account indexes. VersionedTransaction.deserialize reads the standard signature records for versioned data and preserves the message form and its account references.

Legacy population can preserve the compiled message until transaction fields change. Versioned deserialization preserves the compiled message and its lookup records. A versioned message cannot be reconstructed as a legacy transaction without resolving and recompiling its account model.

References: src/…/legacy.ts• L895-969 src/…/versioned.ts• L79-121 src/…/versioned.ts• L21-35 src/…/message.ts• L35-120

Compatibility boundaries

Legacy and versioned transactions share instruction concepts but do not share every parser or builder. The message format and the presence of lookup references determine which path is valid.

Message version detection

The first message byte identifies the format. A legacy message has no version marker. A versioned message sets the high bit and uses the remaining bits for its version number.

The version check is also a safety boundary. Passing versioned bytes to the legacy parser raises an error instead of treating the version marker as a legacy signer count. Passing legacy bytes to a versioned message parser raises the inverse error. Unknown versions remain unsupported.

References: src/…/versioned.ts• L7-37

Address lookup selection

Legacy messages need no external account source because every account key is static. Versioned compilation can move eligible non-signer accounts into lookup records. The compiler keeps signer and invoked-program accounts static so the message retains the account roles needed to authorize and execute instructions.

Missing lookup data, invalid address indexes, or a mismatch in the resolved address set prevents full account-key resolution. This boundary affects decompilation and any code that needs to map an instruction index back to a public key.

References: packages/…/compiled-keys.ts• L106-163 src/…/account-keys.ts• L8-42

API conversion boundaries

Use TransactionMessage.compileToLegacyMessage() when the output must be a legacy message. Use the versioned compile method when the output may use lookup tables. Wrap the chosen result in the matching transaction class.

Do not pass versioned wire data to Transaction.from. Use VersionedTransaction.deserialize for versioned data. Do not expect VersionedTransaction to accept uncompiled instructions or legacy payer fields. For submission and confirmation after serialization, follow Transaction send and confirm.

References: src/…/message.ts• L122-139 src/…/versioned.ts• L18-41 src/…/versioned.ts• L79-121 src/…/legacy.ts• L901-912 src/…/versioned.ts• L21-35

Change checklist

When these files or sections are changed, remember to consider these:

  • Changes to message version parsing must remain aligned with the legacy and versioned wire layouts.
  • Changes to required signer order must preserve the index match between message signers and both transaction signature arrays.
  • Changes to account-key classification or lookup extraction must preserve the account indexes used by compiled instructions and decompilation.
  • Changes to legacy signature defaults must stay aligned with the wire format expected by partial-signing and deserialization flows.
  • Changes to payer selection must be checked in both the legacy transaction path and TransactionMessage compilation because they establish payer state at different times.
  • Changes to static or lookup account limits must remain consistent with the message header and lookup indexes.

Important failure modes

TriggerConsequenceGuard
Missing legacy recent blockhash or durable nonceLegacy message compilation failsSupply one transaction lifetime source before compilation
Missing legacy fee payer and no first signerCompilation cannot form the first required accountSet feePayer or provide a valid first signer
Unknown or non-required signerSigning or signature insertion failsBuild the message first and use only its required signer keys
Missing or invalid legacy signature during default serializationWire serialization failsComplete all signatures or explicitly use partial serialization for an unsigned handoff
Versioned bytes passed to Transaction.fromThe legacy parser rejects the messageUse VersionedTransaction.deserialize
Lookup address not supplied or index out of rangeFull account-key resolution and decompilation failProvide the matching lookup data and preserve the combined account index space
More than 256 static account keysMessage compilation failsReduce static accounts or move eligible accounts to a lookup table
Lookup-table index is 256 or greaterLookup extraction failsKeep each lookup index within the supported byte range
Unsupported message versionDeserialization failsUse a library path that supports the message version

Key files

FileWhy to read it
src/…/legacy.tsDefines legacy transaction inputs, payer choice, signature handling, compilation, and wire conversion
src/…/message.tsShows the shared instruction-level builder and the choice between legacy and versioned messages
src/…/versioned.tsDefines versioned transaction signature slots and versioned wire conversion
packages/…/compiled-keys.tsShows how payer and account roles become message headers, static keys, and lookup-table entries
src/…/versioned.tsDefines message version detection and the versioned deserialization boundary
src/…/account-keys.tsShows how static and looked-up accounts form one index space
test/transaction.test.tsDemonstrates payer ordering, partial signatures, legacy round trips, and versioned transaction boundaries