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