While changes to on chain 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.
The Solana runtime supports two transaction versions:
legacy- older transaction format with no additional benefit
0- added support for Address Lookup Tables
All RPC requests that return a transaction should specify the highest version of transactions they will support in their application using the
maxSupportedTransactionVersion option. Including
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 no
maxSupportedTransactionVersionvalue is set, then only
legacytransactions will be allowed in the RPC response. Therefore, your RPC requests WILL fail if any version
0transactions are returned.
You can set the
maxSupportedTransactionVersion using both the
@solana/web3.js library and JSON formatted requests directly to an RPC endpoint.
@solana/web3.js library, you can retrieve the most recent block or get a specific transaction:
Using a standard JSON formatted POST request, you can set the
maxSupportedTransactionVersion when retrieving a specific block:
Versioned 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.
payeris a valid
Keypairwallet, funded with SOL
Firstly, import the web3.js library and create a
connection to your desired cluster.
We then define the recent
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:
Next, construct a
MessageV0 formatted transaction message with your desired
Then, create a new
VersionedTransaction, passing in our v0 compatible message:
You can sign the transaction by either:
- passing an array of
- call the
transaction.sign()method, passing an array of the required
NOTE: After calling the
transaction.sign()method, all the previous transaction
signatureswill be fully replaced by new signatures created from the provided in
VersionedTransaction has been signed by all required accounts, you can send it to the cluster and
await the response.
legacytransactions, sending a
sendTransactiondoes NOT support transaction signing via passing in an array of
Signersas the second parameter. You will need to sign the transaction before calling