library / How to use Solana / Versioned transactions and lookup tables / HS0107
Static vs looked-up account keys
One TypeScript file pulls recent v0 transactions that use lookup tables from a busy program and prints which keys sit in the message and which came from tables. It shows each invoked program id staying in the static list.
Why the program id stays in the message
A v0 transaction message has two groups of account keys. The static keys are written into the message itself, 32 bytes each. The looked-up keys are written as a one-byte index into an address lookup table, and the runtime resolves them to full addresses before it runs the transaction. Lookup tables exist to shrink the message, so it is natural to expect every key to go through one. A program id does not.
Every instruction names its program with programIdIndex, a position in the combined account list. That list is ordered: the static keys first, then the writable addresses loaded from tables, then the readonly ones. The runtime requires the index of an invoked program to point into the static part. A message that points an instruction at a loaded address is rejected when the transaction is sanitized, before any program runs.
The same holds for signers. The message header counts the required signatures and the fee payer, and the signatures are matched to the first static keys by position, so a signer has to be present in full. What a lookup table can hold is a non-signer account that no instruction invokes as its program. Token mints, token accounts, pools, vaults and authorities that are only read or written are all good candidates.
So a transaction that looks like it ignores its lookup tables for the program id is behaving correctly. The program id costs 32 bytes in the static list, and the other accounts in the instruction shrink to one byte each. If you build transactions with @solana/kit, compressTransactionMessageUsingAddressLookupTables follows the same rule and leaves invoked program addresses in the static list.
The code
Install @solana/kit at 8.6.0, export CARBIUM_KEY and run the file with Node 24. The first argument is a program id and is optional. With no argument it reads a busy aggregator program, whose newest swaps nearly always carry a lookup table.
// HS0107 · Static vs looked-up account keys// https://carbium.sh/library/howsolana/static-vs-looked-up-account-keys// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MITimport { address, createDefaultRpcTransport, createSolanaRpcFromTransport,} from "@solana/kit";const key = process.env.CARBIUM_KEY;if (!key) { console.error("Set CARBIUM_KEY to your Carbium API key."); process.exit(1);}const url = process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh";const rpc = createSolanaRpcFromTransport( createDefaultRpcTransport({ url, headers: { "x-api-key": key } }),);// A busy aggregator program; pass any other program id as the first argument.const program = address(process.argv[2] ?? "JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4");type Tx = { version?: "legacy" | number; transaction: { message: { accountKeys: string[]; instructions: { programIdIndex: number; accounts: number[] }[]; addressTableLookups?: { accountKey: string }[]; }; }; meta: { loadedAddresses?: { writable: string[]; readonly: string[] } } | null;};const sigs = await rpc.getSignaturesForAddress(program, { limit: 15 }).send();const results = await Promise.allSettled( sigs .filter((s) => s.err === null) .map(async (s) => { const tx = await rpc .getTransaction(s.signature, { encoding: "json", maxSupportedTransactionVersion: 1 }) .send(); return { signature: s.signature as string, tx: tx as unknown as Tx | null }; }),);let shown = 0;for (const r of results) { if (r.status === "rejected") { console.error(`getTransaction failed: ${String(r.reason)}`); continue; } const { signature, tx } = r.value; const msg = tx?.transaction.message; const lookups = msg?.addressTableLookups; if (!tx || !msg || !lookups?.length) continue; const staticKeys = msg.accountKeys; const loaded = tx.meta?.loadedAddresses; const fromTables = (loaded?.writable.length ?? 0) + (loaded?.readonly.length ?? 0); console.log( `${signature.slice(0, 12)}... version ${tx.version}: ${staticKeys.length} static keys, ${lookups.length} tables, ${fromTables} loaded addresses`, ); for (const i of new Set(msg.instructions.map((ix) => ix.programIdIndex))) { console.log(` program ${staticKeys[i]} at index ${i}: ${i < staticKeys.length ? "static" : "from a table"}`); } const viaTable = msg.instructions.reduce( (n, ix) => n + ix.accounts.filter((a) => a >= staticKeys.length).length, 0, ); console.log(` instruction account slots filled from tables: ${viaTable}`); if (++shown === 3) break;}if (shown === 0) { console.log("none of the newest transactions used a lookup table; run again or pass another program id");}
run: node main.ts [program-id]
getSignaturesForAddress lists the newest 15 signatures of the program at confirmed commitment, the level @solana/kit fills in when a call leaves it out. Failed transactions are dropped, and each remaining signature goes through getTransaction in Promise.allSettled, so one null or failed read does not end the run. The request passes maxSupportedTransactionVersion: 1, which covers legacy, v0 and v1 transactions, and the json encoding keeps the message indexes as numbers instead of resolving them.
For each transaction that has addressTableLookups, the file prints how many static keys the message carries, how many tables it names and how many addresses came back in meta.loadedAddresses. Then it lists the distinct programIdIndex values and checks each one against the length of the static list. The last line counts the instruction account slots whose index lies past the static keys, which are the accounts the tables supplied.
Reading the output
| Part of the message | Where the key lives | Can a lookup table hold it |
|---|---|---|
| Fee payer and signers | Static keys, first in the list | No |
| Invoked program ids | Static keys | No |
| Writable accounts that do not sign | Static keys or a table's writable indexes | Yes |
| Readonly accounts that do not sign | Static keys or a table's readonly indexes | Yes |
On the default program a swap shows about ten static keys, one table and about as many loaded addresses. Each program line ends in static, and its index is smaller than the static key count. The count of table-filled account slots can run higher than the loaded address count, because one loaded account can fill a slot in several instructions.
A program id can still sit in a lookup table. A router that receives the programs it will call into as plain account arguments may keep them in its table, and in a transaction that never invokes that program directly the table can supply it as an ordinary readonly account. In a transaction that does invoke it, the address goes in the static keys and every instruction that passes it as an account points at that static entry, because a message may not load the same address twice.
On Carbium
getSignaturesForAddress and getTransaction cost 50 cells each, so a run of 15 signatures spends at most 800 cells. The 15 getTransaction reads go out at once, and their rate limit is the one a run meets first: 0.24 calls a second on Free, 1.2 on Dev, 5 on Business and 25 on Pro. Below Pro a batch of 15 goes past that rate, so some reads can come back as 429 with a retry-after hint.
On Free, lower limit in the file so fewer reads go out at once, or run the file on a paid plan. Mainnet carries v1 transactions, so maxSupportedTransactionVersion set to 0 or left out answers -32015 for a v1 transaction or a block holding one, and that error costs nothing. Setting it to 1 covers every version.
Where it ends
The file reports what the message already says. It does not rebuild a transaction, choose which accounts a table should hold or fetch a table's contents. To list the addresses in a table and their order, read the table account itself, as in Lookup table contents reader.
getTransaction can answer null for an older signature that the address index lists, because the index reaches below the validator's ledger floor. The file checks for null and skips it. The newest signatures are the ones it reads, so a run on a busy program rarely hits this.
A sample of 15 may hold no transaction with a lookup table, since legacy and small v0 transactions carry none. The file says so and exits. Run it again or pass a program that routes through many accounts. For a walk through a single transaction's instructions, Transaction explainer goes further.
Legacy transactions have no lookup tables at all, so a program id is always static there, and every other key is too. If you need to fit more accounts into one transaction, a v0 message with a table is the route, and the program ids still count toward the size limit.
When it goes wrong
| what goes wrong | what to do |
|---|---|
| A hand-built v0 message points programIdIndex at a loaded address and the cluster rejects the transaction. | Put the invoked program in the static keys. Build the account list as static keys, then writable loaded, then readonly loaded, and keep every program index below the static count. |
| A signer or the fee payer is placed in a lookup table and the transaction fails to sign or sanitize. | Keep the fee payer and every signer in the static keys. Only non-signer accounts can come from a table. |
| HTTP 429 with a retry-after hint from a run of 15 reads on a small plan. | Lower limit in the file so fewer getTransaction reads go out at once, or use a plan with a higher getTransaction rate. Each read costs 50 cells. |
| Error -32015 from getTransaction for a recent signature. | Pass maxSupportedTransactionVersion: 1 in the call. Leaving it out or using 0 fails for v1 transactions. |
| getTransaction answers null for a signature the list returned. | Skip it. An older signature can sit below the ledger floor even though the address index lists it. Read newer ones. |
Questions
Can I put a program id in a lookup table at all?
You can store the address in a table, and another program can receive it as an account argument. In a transaction that invokes the program, it sits in the static keys and every instruction that passes it as an account points there too.
Why does my transaction still show 30 static keys with a table attached?
The static list holds the signers, the invoked programs and any account you left out of the table. Add the remaining accounts to the table and compress again.
How many bytes does a table save?
Each address moved out of the message goes from 32 bytes to one index byte. A table named in the message costs about 34 bytes of overhead, so small tables with few used entries can lose.
Do legacy transactions use lookup tables?
No. Only v0 messages carry addressTableLookups. A legacy message lists every key in full.