services
Get a key

library / Blockchain ideas / BI0029

Program upgrade watcher

Read the upgrade authority and last deploy slot of any upgradeable Solana program with plain account reads, poll them over HTTPS, and get a printed line with the newest transaction when a program is upgraded, handed to a new authority or frozen.

By Carbium · Developer tools · BI0029 · updated 2026-11-22

01

Who uses it

A program you depend on can change under you. Its upgrade authority, one key recorded on chain, can replace the program's code in a single transaction while the program's address stays the same. An integrator calling a swap router, a wallet team listing a lending protocol and a DAO that keeps funds in a vault program all trust the code that runs today.

Risk and security teams keep a list of the programs their product touches and want a line in a channel when one of them is upgraded, when its authority moves to a new key, or when the authority is removed and the program freezes. Auditors and token-holder communities run the same check after an audit, to see that the authority still points at the multisig the team promised.

A hackathon team gets a demo that needs no wallet and signs nothing. Point it at a program everyone knows and the screen shows who holds the key that can change it.

02

What it reads

An upgradeable program is two accounts. The program account is owned by the upgradeable loader, BPFLoaderUpgradeab1e11111111111111111111111, and holds a pointer: a 4-byte tag with the value 2, then the address of a second account. That second account, the program data account, holds the slot of the last deployment, the upgrade authority and then the program's code.

AccountBytesContent
Program0 to 3tag, 2 for a program
Program4 to 35address of the program data account
Program data0 to 3tag, 3 for program data
Program data4 to 11slot of the last deployment, u64 little-endian
Program data121 when an authority is set, 0 when the program is frozen
Program data13 to 44upgrade authority, 32 bytes, present when byte 12 is 1

solana program set-upgrade-authority <PROGRAM_ID> --new-upgrade-authority <NEW_KEY> rewrites the authority bytes of the program data account, and an upgrade rewrites the slot and the code. With --final in place of a new authority, byte 12 becomes 0 and no later upgrade is possible. Every change appears in the program data account's signature history, next to any other transaction that lists that account.

The request asks for the first 45 bytes only, through dataSlice, so each read returns 45 bytes however large the program is. Programs on any other loader have no authority field here, and the watcher names their owner and skips them.

03

The build

The watcher is one file on @solana/kit and Node 24. It is read-only: no private key, nothing signed or sent.

  1. Take the program ids from the command line and fetch the program accounts in one getMultipleAccounts call at confirmed.
  2. Check the owner and the tag. Print a line for any program that is missing or sits on another loader, and keep the program data address from bytes 4 to 35 for the rest.
  3. Once a poll has finished, wait POLL_MS (10 seconds by default, and any value that is not a positive number falls back to it), then fetch the 45-byte slices of all the program data accounts in one call.
  4. Decode the slot and the authority. The first read of a program prints a WATCHING line with its newest transaction. Later reads print AUTHORITY when the key changed, including a change to or from none, and UPGRADED when the slot moved.
  5. On a change, ask getSignaturesForAddress for one signature on the program data account and print it under the line.
main.ts
// BI0029 · Program upgrade watcher// https://carbium.sh/library/blockchainideas/program-upgrade-watcher// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MITimport { address, createDefaultRpcTransport, createSolanaRpcFromTransport, getAddressDecoder, type Address } 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 ids = process.argv.slice(2);if (ids.length === 0 || ids.length > 100) {  console.error("Usage: node main.ts <program id> [<program id> ...]  (1 to 100 programs)");  process.exit(1);}const POLL_MS = Number(process.env.POLL_MS) > 0 ? Number(process.env.POLL_MS) : 10_000;const LOADER = "BPFLoaderUpgradeab1e11111111111111111111111";const rpc = createSolanaRpcFromTransport(  createDefaultRpcTransport({    url: process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh",    headers: { "x-api-key": key },  }),);const decoder = getAddressDecoder();const base = { commitment: "confirmed", encoding: "base64" } as const;const bytes = (a: { data: readonly [string, string] } | null) => (a ? Buffer.from(a.data[0], "base64") : null);const show = (a: string | null) => a ?? "none (frozen)";const names: string[] = [];const pds: Address[] = []; // program data account of each watched programconst last = new Map<string, { slot: bigint; authority: string | null }>();const gone = new Set<string>(); // programs already reported unreadable// Program account: u32 tag 2, then the program data address.const programs = await rpc  .getMultipleAccounts(ids.map((id) => address(id)), base)  .send()  .catch((e) => {    console.error("start-up lookup failed:", e instanceof Error ? e.message : e);    return process.exit(1);  });programs.value.forEach((acct, i) => {  const b = bytes(acct);  if (!acct || !b) console.log(`${ids[i]} not found`);  else if (acct.owner !== LOADER || b.length < 36 || b.readUInt32LE(0) !== 2)    console.log(`${ids[i]} is owned by ${acct.owner}: not on the upgradeable loader`);  else {    names.push(ids[i]);    pds.push(decoder.decode(b.subarray(4, 36)));  }});async function newest(pd: Address): Promise<string> {  try {    const [s] = await rpc.getSignaturesForAddress(pd, { limit: 1, commitment: "confirmed" }).send();    return s ? `${s.signature} at slot ${s.slot}${s.err ? " (failed)" : ""}` : "none in the 30-day index";  } catch (e) {    return `lookup failed: ${e instanceof Error ? e.message : e}`;  }}// Program data account: u32 tag 3, u64 deploy slot, u8 option, 32-byte authority.async function poll(): Promise<void> {  try {    const res = await rpc.getMultipleAccounts(pds, { ...base, dataSlice: { offset: 0, length: 45 } }).send();    for (const [i, acct] of res.value.entries()) {      const name = names[i];      const b = bytes(acct);      if (!b || b.length < 45 || b.readUInt32LE(0) !== 3) {        if (!gone.has(name)) console.log(`${name} program data unreadable (program closed?)`);        gone.add(name);        continue;      }      gone.delete(name);      const now = { slot: b.readBigUInt64LE(4), authority: b[12] === 1 ? decoder.decode(b.subarray(13, 45)) : null };      const was = last.get(name);      last.set(name, now);      if (!was) {        console.log(`WATCHING ${name} authority ${show(now.authority)} deployed at slot ${now.slot}`);        console.log(`  newest tx on its program data account: ${await newest(pds[i])}`);      } else if (was.authority !== now.authority || was.slot !== now.slot) {        if (was.authority !== now.authority) console.log(`AUTHORITY ${name} ${show(was.authority)} -> ${show(now.authority)}`);        if (was.slot !== now.slot) console.log(`UPGRADED ${name} slot ${was.slot} -> ${now.slot}`);        console.log(`  newest tx on its program data account: ${await newest(pds[i])}`);      }    }  } catch (e) {    console.error("poll failed:", e instanceof Error ? e.message : e);  }}// The next poll is scheduled after this one settles, so polls never overlap.async function loop(): Promise<void> {  await poll();  setTimeout(loop, POLL_MS);}if (pds.length > 0) await loop();

run: CARBIUM_KEY=<YOUR_KEY> node main.ts <PROGRAM_ID> [<PROGRAM_ID> ...]

A poll that throws prints the error, and the next poll runs after the same wait. Because each wait starts when the previous poll ends, a slow round of signature lookups delays the next read and polls never overlap. When two changes land inside one interval the watcher prints the final state once, and the newest signature can belong to a later transaction than the one that moved the slot, so its line carries that transaction's slot for comparison.

04

What it costs

A poll is one getMultipleAccounts call. Cells are the admission charge per call, and account reads cost 10 cells per pubkey, so a list of 20 programs costs 200 cells a poll. The first lookup of the program accounts costs the same once at start. getSignaturesForAddress costs 50 cells and runs once per program at start and once per change.

PlanAccount readsgetSignaturesForAddress
Free0.5 req/s0.24 req/s
Dev15 req/s1.2 req/s
Business50 req/s100 req/s
Pro400 req/s500 req/s

Each program in the list draws 10 cells from the account-read budget. On Free that budget refills at 5 cells a second, which is 0.5 req/s at 10 cells, so a 10-second poll pays for about 5 programs. With a longer list on Free, set POLL_MS to about 2000 per program. The length of the list sets the charge: 100 programs in a call is 1000 cells, or 1001 when the request body passes 4 KiB. That is the largest call a key below Pro can send, because the 1024-cell burst caps it there. getMultipleAccounts takes up to 300 pubkeys on Pro, and the code exits above 100 so the same file runs on every plan.

Limits are per account, so other tools on the same keys draw on the same budget. The start-up lookups are 50 cells each and run back to back, so a long list on Free, at 0.24 req/s, will see some of them fail. The failure is printed next to the program and polling carries on.

05

What to add next

  • A chat message: post each AUTHORITY or UPGRADED line to your chat tool's incoming webhook with fetch.
  • Faster notice: open a logsSubscribe with mentions set to a program data account address and run the same read when a notification arrives. Ordinary calls to a program do not list its program data account, so the stream stays quiet until a deployment or an authority change touches it. A logs-mentions subscription costs 25 credits to open, then 20 credits per MiB sent.
  • Who and what: call getTransaction on the printed signature with maxSupportedTransactionVersion: 1 to read the signers and the instruction. It costs 50 cells.
  • A restart memory: keep the last slot and authority in node:sqlite, so a restart compares with the stored state and prints no WATCHING line for a program that has not changed.
  • The same loop for tokens: mint authorities change the same way, as Token mint supply and authorities reads them, and RWA supply and authority monitor applies that to tokenized assets.
06

Where it ends

  • Polling sees a change within one interval. A deployment between two reads shows up at the next one.
  • Only programs on the upgradeable loader are decoded. A program on any other loader is reported with its owner.
  • An upgrade is staged in a buffer account over many transactions, and the program data account changes at the final one. The staging is not visible here.
  • The authority is printed as a key. The watcher does not say whether that key is a single wallet, a multisig or a governance account.
  • The signature lookup reads the 30-day address index. An empty answer means nothing in 30 days and says nothing about older history.
  • The watcher does not read the program's code or compare it. A deployment of identical bytes still moves the slot, and nothing on the screen says what changed.
07

When it goes wrong

what goes wrongwhat to do
A program prints that it is owned by another account and is not on the upgradeable loader.The program sits on another loader, or the address is not a program id. Check that you passed the program id and not a program data account or a buffer. Nothing is watched for it.
The WATCHING line shows authority none (frozen).The program was frozen and can never be upgraded again. If you expected a key, check that the address is the deployment you meant, since some teams deploy a second copy.
The line says the program data is unreadable.The program was closed, or the program account points at an account that no longer exists. Read the program account with getAccountInfo to see whether it is still there. The line prints once per program.
The newest transaction reads none in the 30-day index.No transaction touched the program data account in 30 days. That is expected for a program that has been stable. The decoded authority and slot are still current.
A call comes back with 429.Raise POLL_MS or shorten the list. The poll prints the error and the next one runs after the wait. Limits are per account, so check what else uses the keys.
The run prints the usage message and exits.The code takes 1 to 100 program ids. Below Pro the 1024-cell burst caps one getMultipleAccounts call at 100 pubkeys, so a longer list needs two watchers on two lists, or Pro, where a call takes up to 300.
08

Questions

How do I set the upgrade authority on a Solana program?

Use the Solana CLI with the current authority's keypair: solana program set-upgrade-authority <PROGRAM_ID> --new-upgrade-authority <NEW_KEY>. By default the new authority's keypair must sign too, unless you pass --skip-new-upgrade-authority-signer-check with a bare pubkey. Pass --final in place of a new key to freeze the program for good.

Can the watcher tell me who the new authority is?

It prints the new key on the AUTHORITY line. Whether that key is a wallet, a multisig or a governance account needs a further read of the key's own account.

Does a changed deploy slot always mean new code?

It means a deployment finished at that slot. The bytes can match the previous ones, so compare the full program data account before and after if you need to know.

How often should I poll?

On Free, 10 seconds fits about 5 programs, and a longer list needs a POLL_MS of about 2 seconds per program. Dev and above fit 100 programs at 10 seconds. Upgrades are rare, so a gap of tens of seconds is usually enough.