---
title: Versioned Transactions
description:
  "Explore the core Solana concepts: transactions, versioned transactions,
  enabling additional functionality in the Solana runtime, address lookup
  tables, and more."
---

Versioned Transactions are the transaction formats that allow for additional
functionality in the Solana runtime, beyond what the original `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](#max-supported-transaction-version).

## 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  |

Jump to the format you are building with:

- [V0 transactions](#v0-transactions) — raise the effective account limit with
  [Address Lookup Tables](/developers/cookbook/transactions/lookup-tables)
- [V1 transactions](#v1-transactions) — fit more into a single transaction, and
  set resource limits in the message itself

For the wire layout of each format, see
[versioned transactions](/docs/core/transactions/versioned-transactions).

## 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`](/docs/rpc/http/getblock) and
[`getTransaction`](/docs/rpc/http/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. The same
> applies one version up: requests that set `0` will fail on version `1`
> transactions. Set the value to the integer `1` to support every format.

## How to set max supported version

You can set the `maxSupportedTransactionVersion` using both the
[`@solana/web3.js`](https://solana-foundation.github.io/solana-web3.js/v1.x/)
library and JSON formatted requests directly to an RPC endpoint.

### Using web3.js

Using the
[`@solana/web3.js`](https://solana-foundation.github.io/solana-web3.js/v1.x/)
library, you can retrieve the most recent block or get a specific transaction:

```js
// connect to the `devnet` cluster and get the current `slot`
const connection = new web3.Connection(web3.clusterApiUrl("devnet"));
const slot = await connection.getSlot();

// get the latest block (allowing for v0 transactions)
const block = await connection.getBlock(slot, {
  maxSupportedTransactionVersion: 0
});

// get a specific transaction (allowing for v0 transactions)
const getTx = await connection.getTransaction(
  "3jpoANiFeVGisWRY5UP648xRXs3iQasCHABPWRWnoEjeA93nc79WrnGgpgazjq4K9m8g2NJoyKoWBV1Kx5VmtwHQ",
  {
    maxSupportedTransactionVersion: 0
  }
);
```

### JSON requests to the RPC

Using a standard JSON formatted POST request, you can set the
`maxSupportedTransactionVersion` when retrieving a specific block:

```shell
curl https://api.devnet.solana.com -X POST -H "Content-Type: application/json" -d \
'{"jsonrpc": "2.0", "id":1, "method": "getBlock", "params": [430, {
  "encoding":"json",
  "maxSupportedTransactionVersion":0,
  "transactionDetails":"full",
  "rewards":false
}]}'
```

## V0 transactions

Version `0` 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.

#### Notes:

- `payer` is a valid `Keypair` wallet, funded with SOL
- `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:

```js
const web3 = require("@solana/web3.js");

// connect to the cluster and get the minimum rent for rent exempt status
const connection = new web3.Connection(web3.clusterApiUrl("devnet"));
let minRent = await connection.getMinimumBalanceForRentExemption(0);
let blockhash = await connection
  .getLatestBlockhash()
  .then((res) => res.blockhash);
```

Create an `array` of all the `instructions` you desire to send in your
transaction. In this example below, we are creating a simple SOL transfer
instruction:

```js
// create an array with your desired `instructions`
const instructions = [
  web3.SystemProgram.transfer({
    fromPubkey: payer.publicKey,
    toPubkey: toAccount.publicKey,
    lamports: minRent
  })
];
```

Next, construct a `MessageV0` formatted transaction message with your desired
`instructions`:

```js
// create v0 compatible message
const messageV0 = new web3.TransactionMessage({
  payerKey: payer.publicKey,
  recentBlockhash: blockhash,
  instructions
}).compileToV0Message();
```

Then, create a new `VersionedTransaction`, passing in our v0 compatible message:

```js
const transaction = new web3.VersionedTransaction(messageV0);

// sign your transaction with the required `Signers`
transaction.sign([payer]);
```

You can sign the transaction by either:

- passing an array of `signatures` into the `VersionedTransaction` method, or
- call the `transaction.sign()` method, passing an array of the required
  `Signers`

> NOTE: After calling the `transaction.sign()` method, all the previous
> transaction `signatures` will be fully replaced by new signatures created from
> the provided in `Signers`.

After your `VersionedTransaction` has been signed by all required accounts, you
can send it to the cluster and `await` the response:

```js
// send our v0 transaction to the cluster
const txId = await connection.sendTransaction(transaction);
console.log(`https://explorer.solana.com/tx/${txId}?cluster=devnet`);
```

> NOTE: Unlike `legacy` transactions, sending a `VersionedTransaction` via
> `sendTransaction` does **NOT** support transaction signing via passing in an
> array of `Signers` as the second parameter. You will need to sign the
> transaction before calling `connection.sendTransaction()`.

## V1 transactions

Version `1` 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.

<CodeTabs storage="cookbook" flags="r">

```typescript !! title="Kit" file=packages/docs-examples/cookbook/transactions/v1-transactions/kit.ts#region=build

```

```go !! title="Go" file=packages/docs-examples/cookbook/transactions/v1-transactions/go/main.go#region=build

```

</CodeTabs>

### 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.

<CodeTabs storage="cookbook" flags="r">

```typescript !! title="Kit" file=packages/docs-examples/cookbook/transactions/v1-transactions/estimate-kit.ts#region=estimate

```

```go !! title="Go" file=packages/docs-examples/cookbook/transactions/v1-transactions/go-estimate/main.go#region=estimate

```

</CodeTabs>

<Callout type="warn">
  The estimate is the exact cost of one simulated run, with nothing to spare.
  Add a margin before relying on it in production.
</Callout>

### Reading a v1 transaction

Fetching a v1 transaction requires setting
[`maxSupportedTransactionVersion`](#max-supported-transaction-version) 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.

<CodeTabs storage="cookbook" flags="r">

```typescript !! title="Kit" file=packages/docs-examples/cookbook/transactions/v1-transactions/kit.ts#region=read

```

```go !! title="Go" file=packages/docs-examples/cookbook/transactions/v1-transactions/go-read/main.go#region=read

```

</CodeTabs>

## More Resources

- using
  [Versioned Transactions for Address Lookup Tables](/developers/cookbook/transactions/lookup-tables#how-to-create-an-address-lookup-table)
- view an
  [example of a v0 transaction](https://explorer.solana.com/tx/h9WQsqSUYhFvrbJWKFPaXximJpLf6Z568NW1j6PBn3f7GPzQXe9PYMYbmWSUFHwgnUmycDNbEX9cr6WjUWkUFKx/?cluster=devnet)
  on Solana Explorer
- read the
  [accepted proposal](https://docs.anza.xyz/proposals/versioned-transactions)
  for Versioned Transaction and Address Lookup Tables
- read about the
  [v1 message format](/docs/core/transactions/versioned-transactions#v1-format)
  and how its resource limits are encoded
