Introducing a new way to review your PRs.

Read the announcement

solana-foundation / solana-go

Go SDK library and RPC client for the Solana Blockchain

View on GitHub

26 documents · Updated Nov 16, 2026

docs / transaction-lifecycle

Transaction lifecycle

The transaction model turns program instructions into a Solana message, adds signatures, and produces the binary form accepted by the network. It also lets callers read the same data back, check signatures, resolve versioned account references, and view the transaction in JSON or a human-readable form. After submission, the transaction confirmation page covers how the client tracks the network result.

Transaction model

Transaction envelope

A Transaction is the signed envelope sent to Solana. Its Message defines what the cluster must execute. Its signature list proves the authority of the signer accounts named by that message.

PartPurpose
MessageHolds account keys, signer and read-only counts, the recent blockhash, instructions, and optional address-table lookups or v1 transaction configuration.
SignaturesHolds one signature for each required signer position. The first signature is also the transaction identifier used after submission.
CompiledInstructionRefers to a program and its accounts by index, then carries the program input bytes.
AccountMetaDescribes an account before compilation as a signer, writable account, or read-only account.

The message header gives the account list meaning. Required signers occupy the first account positions. The header then marks which signed and unsigned accounts are read-only. Instructions use indexes into the resulting account list, so the account order is part of the transaction contract. If a compiled instruction names an account outside the resolved list, account resolution returns an error instead of causing an index-out-of-range panic.

References: transaction.go• L34-44 transaction.go• L137-169 transaction.go• L152-165 transaction_resolve_bounds_test.go• L9-21 message.go• L110-140

Construction flow

The construction flow combines caller instructions with a recent blockhash and produces one compiled message. Account roles become one shared account list, while each instruction becomes a compact set of indexes into that list.

flowchart LR
    I[Program instructions] --> A[Account roles and program IDs]
    B[Recent blockhash] --> M[Compiled message]
    O[Fee payer and version options] --> M
    A --> M
    M --> T[Unsigned transaction]
    T --> S[Signatures]
    S --> W[Serialized transaction]

Instruction compilation

NewTransaction requires at least one instruction. The caller can set the fee payer directly. If it does not, the builder uses the first signer in the first instruction. The builder then combines repeated account references, keeps the strongest account role, places the fee payer first, sets the message header, and maps each program and instruction account to an index.

Address tables can move eligible non-signer accounts out of the static account list. When that happens, the message records the table IDs and index groups instead of placing those public keys directly in the wire message. A transaction built with such lookups is a versioned message.

The builder selects legacy encoding by default. An explicit v0 option selects the versioned lookup-table form without requiring a lookup. A v1 option selects the v1 message rules. TransactionV1Config also selects v1 and carries its inline compute budget settings.

References: transaction.go• L168-223 transaction.go• L227-315 transaction.go• L317-419 transaction.go• L424-591 message_v1.go• L58-103

Signing and validation

Signature collection

Signing always covers the serialized message bytes, not the whole transaction envelope. The message identifies signers by the first NumRequiredSignatures account keys, so signatures must stay in that same order even when private keys arrive in a different order.

PartialSign fills the positions for keys supplied by the caller and leaves the other positions available for another signer. Sign first requires a private key for every required signer. This supports both single-owner signing and multi-party signing without changing the message.

For v1, the signed bytes include the v1 message prefix. This keeps the version part of the signed message and makes signatures compatible with the v1 wire format.

References: transaction.go• L727-765 message.go• L777-786 message.go• L966-968 transaction_v1_test.go• L468-488

Transaction validation

Validation covers the parts the library can check before submission. Binary decoding checks counts, discriminators, declared fields, and available bytes. Signature verification checks that the signature count matches the message header and that every signature verifies against its matching signer and the current message bytes.

Structural sanitization checks the message rules for its selected version. It also checks v1 limits, account uniqueness, inline configuration values, and instruction index bounds. During account resolution, an instruction account index outside the resolved account list is reported as an error rather than a process panic. These checks do not prove that a program will succeed or that the cluster will accept the transaction. The recent blockhash, account state, instruction rules, and cluster conditions remain outside local validation.

References: transaction.go• L152-165 transaction.go• L664-724 transaction.go• L877-901 sanitize.go• L31-41 sanitize.go• L118-161 sanitize.go• L179-220 transaction_resolve_bounds_test.go• L9-21 transaction_v1_test.go• L548-586

Serialization and representation

Binary wire form

Serialization produces the Solana transaction bytes in the order expected by the network. Legacy and v0 transactions put a compact signature count and fixed-size signatures before the encoded message. A v1 transaction puts its versioned message first and then writes one fixed-size signature for each required signer.

If a transaction has fewer signature values than required, binary serialization adds zero-valued signature slots so the wire shape still has one slot per required signer. Those zero values are placeholders, not valid signatures. A transaction must be fully signed before a live send. V1 rejects extra signatures because its wire form has no signature count.

The same binary form can be encoded as base64 for RPC requests or decoded from base64 and base58 input. A binary round trip preserves the message and valid signatures. Slice-level v1 decoding rejects trailing bytes, while streaming decoder use remains suitable when a caller controls the surrounding byte stream.

References: transaction.go• L91-119 transaction.go• L616-653 transaction.go• L664-724 transaction_v1_test.go• L385-419 transaction_v1_test.go• L623-638

External representations

The transaction and message expose different views for different boundaries. Binary encoding is the network form. Base64 and base58 are transport-friendly wrappers around those bytes. JSON is a data view for RPC-shaped transaction content, while the string and tree views help a person inspect accounts, programs, instructions, and signatures.

JSON identifies the message form through version-specific fields. A legacy message omits versioned fields. A v0 message includes addressTableLookups. A v1 message includes transactionConfig and does not include address-table lookups. The v1 JSON form can be decoded and re-encoded without changing the original transaction bytes.

References: transaction.go• L114-119 transaction.go• L767-855 message.go• L223-312 transaction_v1_test.go• L657-678

Message version compatibility

The library supports legacy messages, Solana version 0 messages, and Solana version 1 messages. The legacy and versioned transactions page gives the detailed rules for each form. This page focuses on where the choice affects the transaction lifecycle.

Legacy messages

A legacy message stores all account keys in its static account list. Its first message byte is the required-signer count, so a legacy decoder can identify the form without a version marker. It carries the header, account keys, recent blockhash, and compiled instructions.

Legacy encoding is the default when no address-table lookups or explicit version option is present. It is the simplest form for callers that do not need indirect account addresses.

References: message.go• L98-109 message.go• L390-445 message.go• L453-474 transaction_v1_test.go• L511-527

Versioned messages

A versioned message marks its wire form with a high-bit prefix. The supported V0 form keeps static account keys in the message and uses address-table lookup descriptors for additional writable and read-only accounts. The lookup descriptors contain table IDs and indexes, not the public keys themselves.

Reading a complete account view therefore has two stages. The caller obtains the table contents from the chain, supplies them with SetAddressTables, and then resolves the lookups or asks for all keys. Until that data is available, account metadata and account-index queries return ErrAddressTablesNotSet when lookups are present.

Signing and serialization do not need the lookup tables after the message already has its descriptors. Account inspection does need them because it must map dynamic indexes to public keys. This distinction lets the library preserve the original wire bytes while still offering a resolved view for application logic.

References: message.go• L32-44 message.go• L140-189 message.go• L374-437 message.go• L483-571 message.go• L583-643 transaction_v0_test.go• L13-25 transaction_v0_test.go• L28-45

V1 messages

A v1 message is a versioned message with inline transaction settings instead of address-table lookups. Its transaction configuration can carry a priority fee, compute-unit limit, loaded-account-data limit, and heap-size request. V1 makes these settings part of the message that signers approve.

The transaction builder rejects address tables and ComputeBudget instructions for v1. Callers use TransactionV1Config for the inline settings. V1 also has stricter structural and size limits than the older forms, so construction or sanitization can fail before submission.

V1 uses the 0x81 message prefix and places the message before its fixed signature area. Decoding checks that prefix, reads the signer count from the message header, and requires exactly that many signature slots. Rust SDK golden transactions demonstrate decode, signature verification, sanitization, JSON round trip, and byte-exact re-encoding compatibility.

References: transaction.go• L200-223 transaction.go• L289-315 transaction.go• L593-607 transaction.go• L616-640 message_v1.go• L17-24 message_v1.go• L36-69 transaction_v1_test.go• L99-200

Account and sysvar data

Account codecs

An on-chain Account represents lamports, raw data, owner, executable state, and rent epoch. Its binary codec follows Solana account-state encoding, which is separate from the transaction wire format and from the JSON-RPC account response shape. The account and sysvar codecs page covers this data boundary in detail.

Transaction instructions can name accounts, but account state is decoded through this separate codec after the account is fetched. Keeping these boundaries distinct prevents transaction compact-length fields from being confused with account-state length fields.

References: account.go• L193-215 account.go• L216-252 account.go• L254-329

Sysvar codecs

Sysvars are special Solana accounts that expose cluster data such as time, rent, slot history, and fee state to programs. The library keeps their public keys in the core package and decodes their account data in the sysvar package.

Sysvar data uses standard little-endian bincode. Transaction messages instead use Solana compact length values. The formats serve different boundaries, even when a sysvar public key appears in an instruction account list.

References: sysvar.go• L17-77 sysvar/sysvar_codec.go• L17-39 sysvar/clock.go• L44-99 sysvar/rent.go• L47-99 sysvar/recent_blockhashes.go• L45-93

Change checklist

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

  • Keep the message account order, signer positions, and header counts aligned. A change in account compilation can invalidate both signatures and instruction indexes.
  • Keep compiled instruction account indexes within the resolved account list. Account inspection must return a controlled error for malformed input rather than panic.
  • Keep message version detection aligned across transaction envelopes, message encoding, decoding, and JSON representation.
  • Keep address-table lookup order consistent with writable accounts first and read-only accounts second. Any change affects resolved account indexes and account-role checks.
  • Keep the bytes signed by Sign and checked by VerifySignatures identical to the bytes emitted by message serialization. For v1, that includes the version prefix.
  • Keep v1 inline transaction configuration separate from ComputeBudget instructions and address-table lookups.
  • Keep transaction compact-length encoding separate from account and sysvar bincode codecs.
  • When adding a message version, update the supported-version boundary, envelope discriminator, signature layout, and all representations that infer or emit the version.

Important failure modes

TriggerConsequenceGuard
No instruction is supplied to the transaction builder.Construction fails because there is no message to compile.Add at least one instruction before building.
The fee payer is not set and the first instruction has no signer.The builder cannot determine the payer.Set the fee payer explicitly or provide a signer in the first instruction.
A signature is missing or the signature slice has the wrong length.Sign, VerifySignatures, or Sanitize returns an error.Sign every required signer and keep signatures in message order.
A message is changed after signing.The old signatures fail because they cover different message bytes.Re-sign after changing accounts, instructions, blockhash, or message version.
A compiled instruction refers to an account index beyond the resolved message accounts.Account resolution returns an error instead of usable account metadata.Treat the resolution error as malformed transaction input.
A v1 transaction uses address tables or ComputeBudget instructions.Construction fails because v1 carries inline configuration and does not use those inputs.Use v0 for address tables and TransactionV1Config for v1 compute settings.
A v1 transaction has too many accounts, instructions, signatures, or bytes.Construction or sanitization fails before submission.Stay within the v1 limits and check the serialized size.
A versioned message has lookups but no table contents.Full account, writable-account, and instruction-account inspection returns ErrAddressTablesNotSet.Fetch each table, call SetAddressTables, then resolve or inspect the keys.
A version prefix names an unsupported version, a v1 envelope has the wrong signature area, or the input ends before a declared field.Binary decoding fails instead of producing a usable transaction.Pass bytes from the matching Solana wire format and handle decode errors.
A v1 byte slice has data after the final signature.TransactionFromBytes rejects the slice, although streaming decode leaves the extra data unread.Pass one exact v1 transaction to slice-level decoders or use the streaming decoder for framed data.
An account or sysvar byte stream is decoded with transaction encoding rules.Lengths or fields are read with the wrong format and decoding fails or produces bad state.Use the account or sysvar codec for account data and the transaction codec for messages.

Key files

FileWhy to read it
transaction.goDefines the transaction envelope, builder, signing, signature checks, version-specific binary encoding, and external transaction forms.
message.goDefines message fields, account roles, legacy and V0 encoding, version detection, JSON views, and address-table resolution.
message_v1.goDefines the v1 message shape, inline transaction configuration, and v1 wire compatibility boundary.
sanitize.goDefines structural checks for messages and transactions across legacy, V0, and V1 forms.
account.goDefines on-chain account state and its separate binary codec.
sysvar.goDefines the public keys that identify Solana sysvar accounts used by instructions.
sysvar/sysvar_codec.goStates the common bincode boundary for sysvar account data.
transaction_test.goShows construction, signing, decoding, signature validation, account-role queries, and binary round-trip guarantees for the base transaction flow.
transaction_v0_test.goShows V0 decoding, address-table provisioning, lookup resolution, and byte-preserving re-encoding.
transaction_v1_test.goShows V1 construction and decoding compatibility, inline configuration, strict boundaries, sanitization, and representation round trips.
transaction_resolve_bounds_test.goShows that malformed instruction account indexes return an error instead of causing a panic.
sysvar/sysvars_test.goShows that sysvar codecs match expected sizes, wire values, and round trips.
legacy-and-versioned-transactions.mdChild page for detailed legacy, V0, and V1 message behavior.
account-and-sysvar-codecs.mdChild page for account and sysvar data boundaries.
transaction-confirmation.mdRelated page for the post-submission confirmation flow.