Umbra SDK Docs

convertLegacyTransactionToVersionedTransaction

Umbra SDK reference for Convert Legacy Transaction To Versioned Transaction.

client


convertLegacyTransactionToVersionedTransaction(transaction): VersionedTransaction

Defined in: src/utils/miscellaneous.ts:101

Converts a legacy Solana Transaction to a VersionedTransaction (v0).

Parameters

transaction

Transaction

The legacy Transaction to convert

Returns

VersionedTransaction

A new VersionedTransaction (v0) with the same instructions and accounts

Throws

TransactionConversionError When conversion fails due to missing fee payer, missing recent blockhash, or compilation errors

Remarks

This function converts a legacy Solana Transaction (which uses recentBlockhash) to a modern VersionedTransaction (v0) format. The conversion preserves:

  • All instructions from the original transaction
  • The fee payer (payer key)
  • The recent blockhash (used for transaction expiration)

Requirements:

  • The transaction must have a feePayer set
  • The transaction must have a recentBlockhash set
  • The transaction must have at least one instruction (though empty transactions are technically valid)

Conversion Process:

  1. Extracts instructions, fee payer, and recent blockhash from the legacy transaction
  2. Creates a new TransactionMessage with these components
  3. Compiles the message to v0 format
  4. Wraps it in a VersionedTransaction

Note: This conversion does not preserve transaction signatures. If the original transaction was signed, you will need to re-sign the returned VersionedTransaction.

Examples

// Convert a legacy transaction
const legacyTx = new Transaction();
legacyTx.add(instruction);
legacyTx.feePayer = payerPublicKey;
legacyTx.recentBlockhash = blockhash;

const versionedTx = convertLegacyTransactionToVersionedTransaction(legacyTx);
// versionedTx is now a VersionedTransaction (v0) ready for signing and sending
// Handle conversion errors
try {
  const versionedTx = convertLegacyTransactionToVersionedTransaction(legacyTx);
} catch (error) {
  if (error instanceof TransactionConversionError) {
    console.error('Conversion failed:', error.message);
  }
}