library / AI and blockchain / SI0053
Writable account explainer
A writable tag on an account is a lock the sender asked for in the message header, and it says nothing about intent. Work the flag out from the header counts and lookup tables, then compare it with the lamports that changed.
Where the flag comes from
A transaction message lists every account it touches, and each entry carries two properties the sender chose: whether it signs, and whether the transaction may write to it. An explorer prints the second one as "writable". It is a lock request. For a writable account the runtime takes a write lock for the length of the transaction, so another transaction that reads or writes the same account has to wait its turn. A read-only account takes a shared lock.
The message stores no flag per account. It stores a header of three counts, numRequiredSignatures, numReadonlySignedAccounts and numReadonlyUnsignedAccounts, and orders the account list to match, so each flag follows from the account's index. The order is fixed: writable signers, read-only signers, writable non-signers, read-only non-signers.
- Index below numRequiredSignatures: a signer. It is writable when the index is below numRequiredSignatures minus numReadonlySignedAccounts. Index 0 is the fee payer and always a writable signer.
- Index at or past numRequiredSignatures and inside the static list: a non-signer. It is writable when the index is below the static count minus numReadonlyUnsignedAccounts.
Newer messages add address lookup tables. An account pulled from a table has no entry in the message's own key list. getTransaction returns those accounts in meta.loadedAddresses, as a writable array and a readonly array, and their indexes continue after the static keys with the writable group first. The message picked the flag for each of them when it named the table indexes, so the header counts say nothing about them.
Requested against changed
Because writable is a request, the useful check is whether anything changed. meta.preBalances and meta.postBalances list lamports for every account in the same index order, lookup accounts included. Comparing the two at each index turns the flag into a pair you can read.
| Flag | Lamports | Usual reading |
|---|---|---|
| writable | changed | money moved, a fee was paid, or rent was paid into the account |
| writable | same | a lock on a state account whose data may have changed, or a write that never came |
| readonly | same | an input: a program, a mint, a price account |
| readonly | changed | not possible for a read-only account |
The second row is the one that confuses people. Programs routinely ask for a write lock on an account such as a pool or a config and then write only its data, which leaves the balance alone. The balance comparison misses that, and it cannot tell a write that happened from a lock that went unused.
What it says about a launch
The flag carries no launch signal: payers, transfer recipients and the token accounts a swap debits are writable in any ordinary transaction, whether it is a coffee payment, a mint or a launch. A wallet with the tag next to it was named by one transaction as an account that transaction could change. That is a statement about the transaction, and the wallet appears in it because someone put it there.
A launch guess needs evidence the flag does not hold: how old the wallet is, what the instructions call, who holds mint authority, and who funded the account first. The first of those you can look at with getSignaturesForAddress, but its address index shows only activity inside a 30-day window, so an oldest listed signature near 30 days back means the wallet may be older. The rest is separate reading, and Hot account write-lock report covers the other thing a busy writable account tells you, which is contention between transactions that all want the same lock.
The file
The script takes a program address as its first argument and falls back to a busy one. It lists the program's 10 newest signatures at confirmed commitment, skips failed ones, and fetches the first successful transaction with encoding: "json" and maxSupportedTransactionVersion: 1. A getTransaction call that throws prints its signature and message, and the script moves to the next candidate. Set CARBIUM_KEY first. CARBIUM_RPC_URL overrides the endpoint, which defaults to https://services.carbium.sh.
// SI0053 · Writable account explainer// https://carbium.sh/library/si/writable-account-explainer// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MIT// Compare each account's writable flag with its lamport change. Run: CARBIUM_KEY=... node main.ts [program]import { 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 rpc = createSolanaRpcFromTransport( createDefaultRpcTransport({ url: process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh", headers: { "x-api-key": key }, }),);type Tx = { version?: "legacy" | number; transaction: { message: { header?: { numRequiredSignatures: number; numReadonlySignedAccounts: number; numReadonlyUnsignedAccounts: number }; accountKeys?: string[]; }; }; meta: { preBalances: (bigint | number)[]; postBalances: (bigint | number)[]; loadedAddresses?: { writable: string[]; readonly: string[] } } | null;};const program = address(process.argv[2] ?? "JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4");const listed = await rpc.getSignaturesForAddress(program, { limit: 10, commitment: "confirmed" }).send();let tx: Tx | null = null;let signature = "";for (const s of listed.filter((entry) => entry.err === null)) { try { const got = await rpc.getTransaction(s.signature, { encoding: "json", maxSupportedTransactionVersion: 1, commitment: "confirmed" }).send(); tx = got as unknown as Tx | null; signature = s.signature; if (tx) break; } catch (err) { console.log(`${s.signature} failed: ${err instanceof Error ? err.message : String(err)}`); }}if (!tx) { console.log("no loadable successful transaction in the newest 10 signatures"); process.exit(0);}const { header, accountKeys } = tx.transaction.message;const meta = tx.meta;if (!header || !accountKeys || !meta) { console.log(`${signature} version ${tx.version}: message json has no header or account list, unreadable`); process.exit(0);}const loaded = meta.loadedAddresses ?? { writable: [], readonly: [] };const keys = [...accountKeys, ...loaded.writable, ...loaded.readonly];const staticCount = accountKeys.length;const signers = header.numRequiredSignatures;let idle = 0;console.log(`${signature} version ${tx.version}, ${keys.length} accounts`);keys.forEach((k, i) => { const signer = i < signers; const writable = i >= staticCount ? i - staticCount < loaded.writable.length : signer ? i < signers - header.numReadonlySignedAccounts : i < staticCount - header.numReadonlyUnsignedAccounts; const changed = meta.preBalances[i] !== meta.postBalances[i]; if (writable && !changed) idle++; console.log([i, `${k.slice(0, 6)}..${k.slice(-4)}`, signer ? "signer" : "-", writable ? "writable" : "readonly", i < staticCount ? "static" : "lookup", changed ? "changed" : "same"].join("\t"));});console.log(`${idle} writable accounts kept the same lamports`);
run: node main.ts
The first line prints the signature and the message version. Each row after it has the account index, a short address, signer or not, writable or readonly, static or lookup, and whether lamports changed. The last line counts the writable accounts whose balance stayed put. The usual run costs two calls at 50 cells each, one for getSignaturesForAddress and one for getTransaction, and a null answer on the first candidate adds another getTransaction.
Version 1 matters here. Without it, getTransaction answers -32015 for a v1 transaction, and Transaction version error -32015 shows that error on its own. A message whose json carries no header, which the script prints as unreadable, is left alone, because a guessed layout would print flags that look confident and are wrong.
Where it ends
- The lamport comparison sees balances only. An account whose data changed and whose balance did not shows "same", and reading its data needs the account's own layout.
- The flag is the sender's request. The runtime can treat a requested write on some accounts, such as an invoked program, as read-only when it takes locks, so a writable tag is an upper bound on what the transaction could change.
- The script reads one transaction. Whether a wallet is new, funded by a fresh account or part of a pattern takes the signatures of that wallet and of its funders.
- getSignaturesForAddress reaches back 30 days at most, and a signature it lists can be older than the ledger a node holds, so getTransaction can answer null for it. The script moves to the next candidate, and a program quiet for a long while can run out of them.
- The file reads and prints. It signs nothing and sends nothing.
When it goes wrong
| what goes wrong | what to do |
|---|---|
| getTransaction answers -32015 for a transaction the listing returned. | Pass maxSupportedTransactionVersion: 1 in the config. Absent or 0, a v1 transaction answers -32015 and is not charged. |
| getTransaction answers null for a signature that getSignaturesForAddress listed. | The address index reaches below the ledger floor, so an older signature can list and not load. Handle null, try the next signature and prove the code on the newest ones. |
| The key at an index past the static list is undefined, or the wrong address prints. | Append meta.loadedAddresses.writable and then meta.loadedAddresses.readonly to accountKeys. Pre and post balances already use that combined order. |
| Every non-signer comes out writable, or every signer comes out read-only. | Apply the two read-only counts to their own blocks. numReadonlySignedAccounts trims the signer block and numReadonlyUnsignedAccounts trims the end of the static list. |
| A v1 message prints invented flags. | If the json lacks a header or an account list, print the message as unreadable. Compare version 1 output with an explorer before trusting a new layout. |
Questions
Does writable mean the wallet gained or lost money?
No. It means the sender asked for permission to change the account. Compare preBalances and postBalances at the same index to see whether lamports moved.
Does a writable wallet point to a stealth launch?
No. Payers, recipients and token accounts are all writable in an ordinary transaction. A launch guess needs the wallet's age, the programs called and the mint authority, none of which the flag carries.
Why is a program account usually read-only?
A transaction invokes a program and does not change it, so the sender lists it as an input. Its state lives in other accounts, and those are the writable ones.
What does one run cost?
getSignaturesForAddress and getTransaction cost 50 cells each, so a run that finds a transaction on its first try spends 100 cells. See the rate limits for what your plan allows per second.