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 / transactions

Transaction lifecycle

A transaction is a signed request that groups program instructions into one atomic unit for the Solana cluster. The client assembles the request, binds it to a recent blockhash or durable nonce, signs the resulting message, converts it to wire bytes, sends it through an RPC connection, and waits for a commitment level or an expiry result.

Transaction lifecycle

The lifecycle moves from an instruction-level request to a cluster-visible signature. A legacy transaction and a versioned transaction share this purpose, but they use different message representations and therefore have different construction boundaries. See Legacy and versioned transactions for the representations and Sending, confirmation, and expiry for the send and wait paths.

The main stages are:

  1. Instruction assembly — Programs receive account metadata and input data through TransactionInstruction values.
  2. Message compilation — The payer, account roles, recent blockhash, and instructions become indexed message data.
  3. Signing — Required signers sign the serialized message. Multiple signers can sign the same transaction in full or in parts.
  4. Wire serialization — Signatures and the serialized message form the bytes accepted by the Solana transaction endpoint.
  5. Submission — Connection sends the wire bytes through RPC. The node can run preflight checks and can retry delivery.
  6. Confirmation — The client watches the signature until it reaches the requested commitment or reports a transaction error.
  7. Expiry handling — The client stops waiting when the block height passes the transaction limit or when the durable nonce changes.

The following diagram shows how the client turns instructions into a submitted and confirmed transaction.

flowchart LR
    A[Instructions and account roles] --> B[Compiled message]
    B --> C[Sign message]
    C --> D[Signatures plus message]
    D --> E[Wire bytes]
    E --> F[RPC submission and preflight]
    F --> G[Signature status]
    G --> H[Requested commitment]
    G --> I[Expiry or transaction error]

References: src/…/legacy.ts• L41-59 src/…/legacy.ts• L210-263 src/…/legacy.ts• L662-728 src/connection.ts• L5922-5997 src/connection.ts• L6000-6060

Instruction assembly

An instruction describes one program call. It names the program account, lists the accounts that the program can read or write, marks which accounts must sign, and carries the program input as bytes. A transaction collects these instructions so the cluster can execute them in order as one atomic operation.

Program helpers use a shared data codec to add a program-specific instruction index to encoded fields. This keeps the transaction layer focused on account roles and instruction order while each program defines the meaning of its input data.

References: src/…/legacy.ts• L41-59 src/…/legacy.ts• L85-125 src/instruction.ts• L13-33

Message compilation

A message is the part of a transaction that describes what must be signed and executed. Compilation combines the payer with account metadata from every instruction, removes duplicate accounts, assigns signer and writable roles, and replaces public keys with indexes used by compiled instructions.

The fee payer is placed first and is treated as a writable signer. The message also carries a recent blockhash, which gives a normal transaction its validity window. A durable nonce transaction uses the nonce value in place of the recent blockhash and adds the nonce-advance instruction at the start when needed.

Versioned compilation keeps the same instruction intent but can move extra accounts into address lookup tables. The resulting message has static account keys plus keys resolved from those tables. A versioned transaction can carry a legacy message, a version 0 message, or a version 1 message. Version 1 messages use static account keys and can carry transaction-wide compute settings instead of address table lookups. A versioned message must have its lookup accounts resolved before code can recover the complete account list.

References: src/…/legacy.ts• L374-571 src/…/legacy.ts• L382-410 src/…/legacy.ts• L384-390 src/…/message.ts• L24-39 src/…/message.ts• L122-139 src/…/v0.ts• L188-222 src/…/v0.ts• L79-112 src/…/v1.ts• L43-72 src/…/v1.ts• L75-105

Signing

Signing covers the serialized message rather than the full transaction envelope. Each required signer is identified by its position in the message account list, so a signature is valid only when it matches both the message bytes and the expected public key.

Legacy transactions can be fully signed or partially signed. Supported versioned transactions keep one signature slot for each required signer and allow each matching signer to fill its slot. Before a legacy transaction is serialized for normal sending, required signatures must be present and provided signatures must verify unless the caller explicitly changes the legacy serialization settings. Version 1 messages cannot be signed through this path because their message serialization is not supported.

Changing transaction fields after signing changes the message bytes and can invalidate the signatures. The blockhash or nonce used for signing must therefore be selected before the final signing step.

References: src/…/legacy.ts• L647-728 src/…/legacy.ts• L767-832 src/…/versioned.ts• L18-41 src/…/versioned.ts• L43-77 src/…/versioned.ts• L94-126 src/…/versioned.ts• L124-156 src/…/v1.ts• L129-133 src/…/ed25519.ts• L1-20

Wire serialization

Wire serialization produces the byte sequence that the RPC node forwards to the cluster. It places a compact signature count first, followed by fixed-size signatures, and then the serialized legacy or versioned message.

Legacy message bytes are identified by their unversioned header. Version 0 message bytes carry a version prefix and can include address table lookup records. Version 1 transactions use a distinct version-prefixed layout that places their signatures after the message. This client can read that layout, but MessageV1 does not serialize message bytes, so it cannot create a version 1 wire transaction. The serialized transaction must fit the network packet size limit.

References: src/…/legacy.ts• L797-865 src/…/versioned.ts• L43-121 src/…/legacy.ts• L160-263 src/…/v0.ts• L224-308 src/…/v1.ts• L129-133 src/…/v1.ts• L135-241 src/…/constants.ts• L1-19 src/…/versioned.ts• L8-37

Submission and confirmation

Connection is the boundary between a signed transaction and the Solana RPC node. It accepts a legacy transaction with signers or an already signed versioned transaction, then sends the serialized bytes as base64 through the sendTransaction RPC method.

For a legacy blockhash transaction, sendTransaction obtains a blockhash and its last valid block height before signing. The helper then sends the signed bytes. For a durable nonce transaction, it uses the nonce already attached to the transaction. A versioned transaction is already compiled and signed, so the connection serializes and sends it without adding signers.

Confirmation uses the returned transaction signature. The client combines a signature subscription with status checks, then applies the requested commitment. A successful result has no transaction error. A reported transaction error becomes a SendTransactionError, which retains the signature and can load full logs from the connection.

References: src/connection.ts• L5922-5997 src/connection.ts• L6000-6060 packages/…/send-and-confirm-transaction.ts• L24-117 src/connection.ts• L3891-4007 src/errors.ts• L4-90

Expiry handling

Expiry handling tells the caller when the client can no longer wait for a valid result. The preferred blockhash strategy compares the current block height with the blockhash's lastValidBlockHeight. The durable nonce strategy reads the nonce account and treats a changed nonce as invalidation of the pending transaction.

The older signature-only confirmation path has no transaction-specific expiry data. It uses a time limit instead, so a timeout means that the client does not know whether the transaction succeeded or failed. Callers should use a block-height or durable-nonce strategy when the transaction provides the required data.

The three expiry outcomes have different meanings:

StrategyExpiry signalCaller-visible result
BlockhashCurrent block height exceeds the last valid heightTransactionExpiredBlockheightExceededError
Durable nonceThe stored nonce no longer equals the signed nonceTransactionExpiredNonceInvalidError
Legacy timeoutThe wait period ends before confirmationTransactionExpiredTimeoutError; outcome is unknown

Confirmation also supports an abort signal for the block-height and durable-nonce strategies. When confirmation ends, the client removes its signature subscription and stops the expiry checks.

References: src/connection.ts• L309-357 src/connection.ts• L4009-4059 src/connection.ts• L4062-4202 src/connection.ts• L4205-4257 src/…/expiry-custom-errors.ts• L1-48

Legacy and versioned boundaries

Legacy and versioned transactions represent the same high-level request but do not share the same construction API. A legacy Transaction owns its instructions and compiles them into a legacy Message. A VersionedTransaction owns a compiled VersionedMessage, which may be a legacy message, a version 0 message, or a version 1 message. Version 1 is a read-only format in this client because its message cannot be serialized for signing or sending.

The boundary matters when sending and when reading account keys. Legacy messages contain all account keys directly. Version 0 messages contain static keys and lookup references, so the lookup table accounts or resolved lookup keys are needed to reconstruct the full instruction view.

ConcernLegacy formatVersioned format
ConstructionAdd instructions to TransactionCompile a TransactionMessage into a versioned message
Account setAll keys are in the messageStatic keys can be combined with lookup-table keys for version 0; version 1 uses static keys
Signing inputSerialized legacy messageSerialized versioned message
Send entrysendTransaction(transaction, signers)sendTransaction(versionedTransaction, options)
Wire readTransaction.from(...)VersionedTransaction.deserialize(...); version 1 has a separate readable layout

References: src/…/legacy.ts• L210-323 src/…/versioned.ts• L13-41 src/…/versioned.ts• L79-122 src/…/message.ts• L122-139 src/…/versioned.ts• L5-37 src/…/v1.ts• L75-105 src/connection.ts• L5928-5959

Change checklist

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

  • Changes to message account ordering or signer counts must stay aligned with signature placement and wire deserialization for both formats.
  • Changes to blockhash acquisition must preserve the matching lastValidBlockHeight passed to confirmation.
  • Changes to durable nonce construction must preserve the nonce account, signed nonce value, nonce instruction, and minimum context slot as one confirmation contract.
  • Changes to version prefix handling must keep legacy detection separate from supported version 0 and version 1 decoding.
  • Changes to version 1 message support must keep its config mask, message layout, and read-only serialization status aligned with transaction handling.
  • Changes to lookup-table account resolution must preserve the index order used by compiled instructions.
  • Changes to send options must keep preflight, retry, and minimum-slot settings consistent between signed and raw send paths.

Important failure modes

TriggerConsequenceGuard
Missing recent blockhash or durable nonceMessage compilation fails before signingSet the transaction lifetime source before compilation
Missing fee payerThe transaction cannot define its first required signerSet feePayer or provide a valid first signer
Missing or invalid required signatureSerialization rejects the transaction or the cluster rejects itSign every required account and verify the message before sending
Version 0 lookup table is not resolvedFull account keys cannot be read or decompiledSupply the matching lookup-table accounts or resolved lookup keys
Version 1 message is sent for signing or serializationMessage serialization fails because version 1 message encoding is not supportedTreat version 1 as a readable format until write support exists
Wire transaction exceeds the packet limitSerialization fails and no transaction is sentReduce instruction data or account use
Block height passes the last valid heightConfirmation throws a block-height expiry errorStop retrying that signed transaction and build a new one
Durable nonce changes before confirmationConfirmation throws a nonce-invalid errorTreat the signed transaction as expired and inspect the signature
Legacy confirmation times outThe final transaction result is unknownQuery the signature before deciding whether to retry
Preflight or send RPC rejects the transactionSendTransactionError reports the failure and may expose logsRead the error and call getLogs() when more detail is needed

Key files

FileWhy to read it
src/…/legacy.tsShows instruction ownership, legacy message compilation, signing, verification, and wire serialization.
src/…/message.tsShows the shared instruction model and the choice between legacy and version 0 message compilation.
src/…/legacy.tsDefines the legacy message shape and its account and instruction encoding.
src/…/v0.tsDefines version 0 messages and their address lookup table boundary.
src/…/v1.tsDefines the readable version 1 message shape and its transaction-wide compute settings.
src/…/versioned.tsShows signing, serialization, and deserialization for compiled versioned messages.
src/connection.tsDefines transaction submission, confirmation strategies, commitment handling, and expiry checks.
packages/…/send-and-confirm-transaction.tsConnects legacy transaction signing and sending to the right confirmation strategy.
src/…/send-and-confirm-raw-transaction.tsConnects pre-signed wire bytes to explicit or legacy confirmation behavior.
src/…/expiry-custom-errors.tsDefines the distinct errors for block-height expiry, nonce invalidation, and timeout.