2

I'm running into an error with transactions overruning UInt8Array buffer, and I see that I need to save space using versioned transactions and address lookup tables.

How can I create one using the @solana/web3.js library? Ideally I'd like to pass in keys and create it a separate transaction.

1

1 Answer 1

2

You can use AddressLookupTableProgram.createLookupTable to create an LUT and then AddressLookupTableProgram.extendLookupTable to add addresses to it. Here's a quick snippet:

export const createLookupTable = async (
  wallet: NodeWallet,
  connection: web3.Connection,
  keys: string[]
) => {
  const slot = await connection.getSlot();

  const [lookupTableInst, lookupTableAddress] =
    web3.AddressLookupTableProgram.createLookupTable({
      authority: wallet.publicKey,
      payer: wallet.publicKey,
      recentSlot: slot,
    });

  const extendInstruction = web3.AddressLookupTableProgram.extendLookupTable({
    payer: wallet.publicKey,
    authority: wallet.publicKey,
    lookupTable: lookupTableAddress,
    addresses: keys.map((key) => new web3.PublicKey(key)),
  });

  return {
    lutIx: lookupTableAddress,
    createLutIx: lookupTableInst,
    extendIx: extendInstruction,
  }
};

Additionally, here's a full gist outlining different situations for creating lookup tables: https://gist.github.com/joeymeere/b38153fb478a5c19f1ea6a9e51c8f185

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.