legacy format
supports.
While changes to onchain programs are NOT required to support the new
functionality of versioned transactions (or for backwards compatibility),
developers WILL need update their client side code to prevent
errors due to different transaction versions.
Current Transaction Versions
The Solana runtime supports three transaction versions:| Version | Size limit | Address Lookup Tables | Resource limits |
|---|---|---|---|
legacy | 1,232 bytes | Not supported | ComputeBudget instructions |
0 | 1,232 bytes | Supported | ComputeBudget instructions |
1 | 4,096 bytes | Removed | Set in the message config |
- V0 transactions — raise the effective account limit with Address Lookup Tables
- V1 transactions — fit more into a single transaction, and set resource limits in the message itself
Max supported transaction version
All RPC requests that return a transaction should specify the highest version of transactions they will support in their application using themaxSupportedTransactionVersion option, including
getBlock and
getTransaction.
An RPC request will fail if a Versioned Transaction is returned that is higher
than the set maxSupportedTransactionVersion. (i.e. if a version 0
transaction is returned when legacy is selected)
WARNING: If nomaxSupportedTransactionVersionvalue is set, then onlylegacytransactions will be allowed in the RPC response. Therefore, your RPC requests WILL fail if any version0transactions are returned. The same applies one version up: requests that set0will fail on version1transactions. Set the value to the integer1to support every format.
How to set max supported version
You can set themaxSupportedTransactionVersion using both the
@solana/web3.js
library and JSON formatted requests directly to an RPC endpoint.
Using web3.js
Using the@solana/web3.js
library, you can retrieve the most recent block or get a specific transaction:
@solana/web3.js 1.x is no longer actively maintainedIt receives critical fixes only. Use Kit for new code. To migrate existing code, follow the Kit upgrade guide, or the web3.js v3 migration guide to keep the class-based API.To run this code, install 1.x with npm install @solana/web3.js@1. A plain npm install @solana/web3.js installs v3, which this code doesn’t run on.JSON requests to the RPC
Using a standard JSON formatted POST request, you can set themaxSupportedTransactionVersion when retrieving a specific block. Slot
518104023 holds legacy, v0 and v1 transactions; any recent slot from
getSlot works too:
V0 transactions
Version0 transactions can be created similar to the older method of creating
transactions. There are differences in using certain libraries that should be
noted.
Below is an example of how to create a Versioned Transaction, using the
@solana/web3.js library, to send perform a SOL transfer between two accounts.
@solana/web3.js 1.x is no longer actively maintainedIt receives critical fixes only. Use Kit for new code. To migrate existing code, follow the Kit upgrade guide, or the web3.js v3 migration guide to keep the class-based API.To run this code, install 1.x with npm install @solana/web3.js@1. A plain npm install @solana/web3.js installs v3, which this code doesn’t run on.Notes:
payeris a validKeypairwallet, funded with SOLtoAccounta validKeypair
connection to your desired
cluster.
We then define the recent blockhash and minRent we will need for our
transaction and the account:
array of all the instructions you desire to send in your
transaction. In this example below, we are creating a simple SOL transfer
instruction:
MessageV0 formatted transaction message with your desired
instructions:
VersionedTransaction, passing in our v0 compatible message:
- passing an array of
signaturesinto theVersionedTransactionmethod, or - call the
transaction.sign()method, passing an array of the requiredSigners
NOTE: After calling theAfter yourtransaction.sign()method, all the previous transactionsignatureswill be fully replaced by new signatures created from the provided inSigners.
VersionedTransaction has been signed by all required accounts, you
can send it to the cluster and await the response:
NOTE: Unlikelegacytransactions, sending aVersionedTransactionviasendTransactiondoes NOT support transaction signing via passing in an array ofSignersas the second parameter. You will need to sign the transaction before callingconnection.sendTransaction().
V1 transactions
Version1 raises the transaction size limit to 4,096 bytes and moves the
resource limits out of ComputeBudget instructions and into the message itself.
Address Lookup Tables are not available on v1 — every account a v1 transaction
touches is listed in the message.
Building a v1 transaction
A v1 message is assembled through the same pipeline as a legacy or v0 one; the difference is the config it carries. The compute unit limit and loaded accounts data size limit both default to zero, so a v1 transaction that leaves them unset always fails.Kit
Output
Estimating the resource limits
Rather than hardcoding the limits, simulate the transaction to measure them. Simulation runs with both limits raised to the runtime maximum, so it cannot fail for want of the resources it is measuring.Kit
Output
The estimate is the exact cost of one simulated run, with nothing to spare.
Add a margin before relying on it in production.
Reading a v1 transaction
Fetching a v1 transaction requires settingmaxSupportedTransactionVersion to the
integer 1. The compiled message stores the config as a bitmask plus a
positional list, so decompile it to address the fields by name.
Kit
Output
More Resources
- using Versioned Transactions for Address Lookup Tables
- view an example of a v0 transaction on Solana Explorer
- read the accepted proposal for Versioned Transaction and Address Lookup Tables
- read about the v1 message format and how its resource limits are encoded