services
Get a key

library / Blockchain ideas / BI0020

Governance proposal tracker

Read a governance program's recent transactions, the proposals they touch and each proposal's state, then follow new activity live, from one hosted RPC and WebSocket. It comes with the costs, the limits and a runnable main.ts.

By Carbium · DAO and treasury · BI0020 · updated 2026-11-22

01

Who uses it

A DAO that votes on chain publishes every proposal, yet the people who should vote often hear about one late, if at all. The tracker answers three questions in one terminal: what happened in governance lately, which proposals are open for voting, and what just changed.

Token holders and delegates want to know a vote is open before it closes. A grants team sees each proposal's state at start and every new instruction on it live. An analytics team counts proposals created and votes cast per week from the instruction names, and failed transactions from each signature's error field.

The code targets the SPL Governance program, which many DAOs share, and takes another deployment of it as an argument. A hackathon team can aim it at one DAO by filtering on that DAO's governance address, which the output prints beside every proposal.

02

What it reads

OutputWhere it comes fromExample
Instruction namesthe GOVERNANCE-INSTRUCTION: lines in each transaction's log messagesCreateProposal, CastVote
Proposal accountsaccounts named in those transactions, owned by the program, whose first byte is 14an address and its governance
Proposal statebyte 65 of the account data, read as Draft, SigningOff, Voting, Succeeded, Executing, Completed, Cancelled, Defeated, ExecutingWithErrors or VetoedVoting
Live activitya logsNotification from logsSubscribe with a mention of the programok, a signature, CastVote

A proposal account holds more than its state: a title, vote tallies and timestamps. The state sits after two addresses, ahead of the first variable-length field, so plain offsets decode it with no schema library. The title and tallies sit behind variable-length fields, and reading them takes a real decoder. Check the offsets against the program version your DAO deploys.

03

The build

The tracker is one file that needs @solana/kit and what Node 24 ships. It is read-only: no private key, nothing signed or sent.

  • Take the program address from the command line, or use the SPL Governance program.
  • Create the RPC client once, with the key in x-api-key, and reuse it for every call, each one reading at confirmed commitment.
  • Call getSignaturesForAddress on the program for the six newest signatures and mark each ok or FAILED.
  • Call getTransaction for each signature with maxSupportedTransactionVersion: 1 and the json encoding. A null answer is skipped and named. Print the instruction names from the logs and collect the account keys. Each call has its own try.
  • Call getMultipleAccounts on up to 100 of those keys at base64. Keep the accounts the program owns whose first byte is 14, and print each address, its state and its governance.
  • Open one WebSocket with the key as ?api-key= and send logsSubscribe with { mentions: [program] }. Print each notification with its instruction names.
  • On a close, print its code and reason, reconnect two seconds later and subscribe again.
main.ts
// BI0020 · Governance proposal tracker// https://carbium.sh/library/blockchainideas/governance-proposal-tracker// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MITimport { address, createDefaultRpcTransport, createSolanaRpcFromTransport, getAddressDecoder } from "@solana/kit";const key = process.env.CARBIUM_KEY;if (!key) { console.error("Set CARBIUM_KEY to your Carbium API key."); process.exit(1); }// SPL Governance, the program many DAOs share. Pass another deployment as the first argument.const program = address(process.argv[2] ?? "GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw");const WS_URL = `${process.env.CARBIUM_WS_URL ?? "wss://services.carbium.sh"}/?api-key=${key}`;const rpc = createSolanaRpcFromTransport(createDefaultRpcTransport({  url: process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh",  headers: { "x-api-key": key },}));const STATES = ["Draft", "SigningOff", "Voting", "Succeeded", "Executing", "Completed", "Cancelled", "Defeated", "ExecutingWithErrors", "Vetoed"];const PROPOSAL_V2 = 14; // account type byte; the state byte sits at offset 65const decoder = getAddressDecoder();type Tx = { meta: { logMessages?: string[] | null } | null; transaction: { message: { accountKeys?: string[] } } };const why = (e: unknown): string => (e instanceof Error ? e.message : String(e));const instructions = (logs?: readonly string[] | null): string =>  (logs ?? []).flatMap((l) => l.match(/GOVERNANCE-INSTRUCTION: (\w+)/)?.[1] ?? []).join(",") || "-";async function recent(): Promise<void> {  const sigs = await rpc.getSignaturesForAddress(program, { limit: 6, commitment: "confirmed" }).send();  const keys = new Set<string>();  for (const s of sigs) {    try {      const tx = (await rpc        .getTransaction(s.signature, { maxSupportedTransactionVersion: 1, encoding: "json", commitment: "confirmed" })        .send()) as unknown as Tx | null;      // The address page can list a signature whose transaction is below the ledger floor.      if (!tx) { console.log(`skipped ${s.signature} (no transaction behind it)`); continue; }      console.log(`${s.err ? "FAILED" : "ok"} ${s.signature} ${instructions(tx.meta?.logMessages)}`);      for (const k of tx.transaction.message.accountKeys ?? []) keys.add(k);    } catch (e) { console.error(`getTransaction ${s.signature.slice(0, 12)} failed:`, why(e)); }  }  // At most 100 pubkeys a call: below Pro the burst caps getMultipleAccounts there.  const list = [...keys].slice(0, 100).map((k) => address(k));  if (!list.length) return;  const { value } = await rpc.getMultipleAccounts(list, { encoding: "base64", commitment: "confirmed" }).send();  value.forEach((a, i) => {    if (!a || a.owner !== program) return;    const data = Buffer.from(a.data[0], "base64");    if (data[0] !== PROPOSAL_V2) return;    const governance = decoder.decode(data.subarray(1, 33));    console.log(`proposal ${list[i]} ${STATES[data[65] ?? 99] ?? "unknown"} governance ${governance}`);  });}const connect = (): void => {  const ws = new WebSocket(WS_URL);  ws.onopen = () => ws.send(JSON.stringify({ jsonrpc: "2.0", id: 1, method: "logsSubscribe", params: [{ mentions: [program] }, { commitment: "confirmed" }] }));  ws.onmessage = (ev) => {    const msg = JSON.parse(String(ev.data));    if (msg.id === 1) {      console.log(msg.error ? `subscribe refused: ${msg.error.message}` : `watching ${program}, subscription ${msg.result}`);      return;    }    if (msg.method !== "logsNotification") return;    const { signature, err, logs } = msg.params.result.value;    console.log(`live ${err ? "FAILED" : "ok"} ${signature} ${instructions(logs)}`);  };  ws.onclose = (ev) => { console.log(`socket closed ${ev.code} ${ev.reason || "-"}, reconnecting`); setTimeout(connect, 2000); };  ws.onerror = () => ws.close();};recent().catch((e) => console.error("recent activity failed:", why(e))).finally(connect);

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

Mainnet carries v1 transactions, and getTransaction answers -32015 for one when the version value is absent or 0. Passing 1 avoids that; the failure is explained in Transaction version error -32015. The address page can also list a signature whose transaction has fallen below the validator's ledger floor, so getTransaction answers null for it and the code skips it.

04

What it costs

The first run makes one signatures call at 50 cells, six transaction lookups at 50 cells each (300 in all) and one account read. getMultipleAccounts bills 10 cells for every pubkey, so a full 100-key call is 1000 cells, or 1001 when the request body goes past 4 KiB, as 100 addresses do. Pro accepts up to 300 pubkeys in a call. On lower plans the 1024-cell burst limits a call to 100, so the code never sends more. The total comes to at most 1,351 cells.

The socket is metered in credits. A logs subscription filtered by mention costs 25 credits to open and 20 credits for each MiB it sends. The volume a program's logs reach varies by week, so check your credit balance after a few hours of running. Every 50 MiB delivered in a month costs 1,000 credits.

PlanCreditsgetTransaction, req/sgetSignaturesForAddress, req/sAccount reads, req/s
Free ($0)500K once, at sign-up0.240.240.5
Dev ($20)10M per month1.21.215
Business ($250)50M per month510050
Pro ($500)200M per month25500400

A cell is what admission charges for a call, and each table figure is a calls-per-second ceiling for that call class. Six getTransaction calls in a row cost 300 cells. At 0.24 req/s on Free, a deeper lookback needs a slower loop or a bigger plan. A call that fails prints its reason and the run continues with what it has. Other tools on the same account draw on the same budget. Free allows 5 sockets, and the tracker opens one. Credits meter RPC and WebSocket work alike.

$A mention matches every transaction that names the program, and each notification carries that transaction's full log lines. Credits follow the bytes, so a busy program drives the bill whatever number of proposals you follow.
05

What to add next

  • An alert: when a vote is cast on a governance you follow, read its proposal again and post to a channel when the state reaches Voting or Succeeded.
  • Titles and tallies: decode the whole proposal account to print the title and the vote totals.
  • Turnout: read the governing token's supply with getTokenSupply and compare it with the votes cast. Token mint supply and authorities covers that read.
  • A store: write each instruction and state change to SQLite with node:sqlite, so you keep a history longer than the 30-day address index. Its history begins at the first run.
  • A page: serve the latest snapshot from a small HTTP server and push changes to the browser with server-sent events. For the funds a DAO holds, pair it with the DAO treasury dashboard.
06

Where it ends

  • One program at a time. A fork that changed the instruction log or the proposal layout needs its own log pattern and account layout.
  • A proposal shows up once a transaction among the six newest touches it. The tracker never scans the program's accounts, so an open proposal that nobody has voted on lately stays out until its next transaction.
  • It prints the state and the governance address. Title, description, vote tallies and voter lists need the full decode.
  • Signatures reach 30 days back at most, the extent of Carbium's address index. An empty page past that is the index's age limit and says nothing about older proposals.
  • A mention matches failed transactions too, so a rejected vote appears in the feed marked FAILED and changes no state.
  • The byte offsets come from the program's published layout. A program upgrade that changes it breaks the state column before it breaks anything else.
07

When it goes wrong

what goes wrongwhat to do
getTransaction answers null for a signature the program lists.The address index reaches below the validator's ledger floor, so an older signature can list without a transaction behind it. The code prints it as skipped. Keep the lookback short and prove the run on the newest signatures.
getTransaction answers -32015.The call left out maxSupportedTransactionVersion or set it to 0, and the transaction is v1. Pass maxSupportedTransactionVersion: 1 with an encoding.
Instruction names print but no proposal lines follow.The six newest transactions touched no proposal account, or the program you named uses another layout. Raise the limit within your plan, or check the program address against the DAO's own deployment.
getMultipleAccounts answers 429 or an error.The tracker prints the reason and still opens the socket. Send fewer keys, since each pubkey costs 10 cells and the account's keys share one limit, then run it again.
The subscribe reply is an error, or the socket closes straight away.The close code and reason print before each reconnect. Check CARBIUM_KEY and that the account is under its socket cap (Free carries 5). A refused subscription costs nothing; one that opens costs 25 credits, and so does every reconnect the code makes.
The program exits at start with an address error.The argument is not a valid base58 address. Copy the program address again, with no spaces or quotes inside.
08

Questions

Does it work for Squads multisigs?

No. It reads the SPL Governance log lines and account layout. Another governance program needs its own instruction pattern and its own offsets.

Why read accounts from transactions instead of listing every proposal?

A transaction names the accounts it touches, so a few calls find the live proposals. The tracker never scans the program's accounts, which keeps its cost at the cells shown above.

Will it run on the Free plan?

A short run fits: at most 1,351 cells at start-up and one socket. Free allows 0.24 getTransaction calls a second, so run it and watch for 429s. A failed call prints its reason and the stream keeps going.

How far back can it look?

Thirty days of signatures at most, the extent of Carbium's address index. To keep a longer history, store each instruction and state as the feed delivers it.