2

I want to send the transactions in which there are multiple transaction instructions so, Is there any way to send these all transaction instructions through versioned transaction or address lookup table as to make it compressed ?

1 Answer 1

10

Each address in a transaction instruction takes 32 bytes but when addresses are present in an on-chain LUT(short for Address Lookup Table), they can be referenced using a 1-byte index. A single LUT can contain up to 256 addresses.

To use them, first you need to create a LUT and extend it with the addresses your transaction will use during execution. You can get the instruction to create a LUT and its address by invoking the static method createLookupTable of the AddressLookupTableProgram

import {
  AddressLookupTableProgram,
  TransactionInstruction,
  TransactionMessage,
  VersionedTransaction,
} from "@solana/web3.js";

const [createLutInstr, lutAddress] = AddressLookupTableProgram.createLookupTable({
          authority: authority,
          payer: authority,
          recentSlot: await connection.getSlot("confirmed")
        });

Adding addresses to LUT is called extending. To get the instruction to do that, you invoke the extendLookupTable method of the LUT program. While extending the LUT, you need to respect the 1232 size limit of a Solana transaction and issue several transactions each extending the LUT with ~20 addresses.

const extendInstruction = AddressLookupTableProgram.extendLookupTable({
          payer: payer
          authority: authority,
          lookupTable: lutAddress,
          addresses: addresses //List of addresses,
        });

Now, in order to create a VersionedTransaction, you first need to construct a MessageV0 object which will contain both the TransactionInstructions and a list of AddressLookupTableAccount which contain the addresses your transaction would reference during execution.

You can fetch the AddressLookupTableAccount object by providing its address to getAddressLookupTable

const lookupTableAccount = (await connection.getAddressLookupTable(lutAddress)).value!;

and now you can create a VersionedTransaction by

    const lutAccounts = [lookupTableAccount, ...];
    const message = new TransactionMessage({
      payerKey: payer
      recentBlockhash: blockhash,
      instructions: listOfTransactionInstructions,
    }).compileToV0Message(lutAccounts);

    const tx = new VersionedTransaction(message);

This way, you can compress the size of your transaction by a big deal allowing you to pack more instructions inside it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.