Versioned Transactions
Versioned Transactions
Versioned Transactions are the new transaction format that allow for additional functionality in the PUT runtime, including Address Lookup Tables.
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.
Current Transaction Versions
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 the maxSupportedTransactionVersion 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 no maxSupportedTransactionVersion value is set, then only legacy transactions will be allowed in the RPC response. Therefore, your RPC requests WILL fail if any version 0 transactions are returned.
How to set max supported version
You can set the maxSupportedTransactionVersion using both the @put/web3.js library and JSON formatted requests directly to an RPC endpoint.
Using web3.js
Using the @put/web3.js library, you can retrieve the most recent block or get a specific transaction:
JSON requests to the RPC
Using a standard JSON formatted POST request, you can set the maxSupportedTransactionVersion when retrieving a specific block:
How create a Versioned Transaction
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 @put/web3.js library, to send perform a PUT transfer between two accounts.
Notes:#
payer is a valid Keypair wallet, funded with PUT
toAccount a valid Keypair
Firstly, import the web3.js library and create a connection to your desired cluster.
We then define the recent blockhash and minRent we will need for our transaction and the account.
Create an array of all the instructions you desire to send in your transaction. In this example below, we are creating a simple PUT transfer instruction:
Next, construct a MessageV0 formatted transaction message with your desired instructions:
Then, create a new VersionedTransaction, passing in our v0 compatible message:
You can sign the transaction by either:
After your VersionedTransaction has been signed by all required accounts, you can send it to the cluster and await the response.
More Resources
using Versioned Transactions for Address Lookup Tables
view an example of a v0 transaction on PUT Explorer
read the accepted proposal for Versioned Transaction and Address Lookup Tables
Last updated