---
id: BI0022
title: "Live mint progress counter"
url: https://carbium.sh/library/blockchainideas/live-mint-progress-counter
collection: Blockchain ideas
category: Creator and membership
revision: 1
updated: 2026-11-22
author: Carbium
code: MIT (LICENSE in the zip); text: all rights reserved, Carbium Corporation
---

# Live mint progress counter

A mint counter that updates as each mint lands. One logsSubscribe on Carbium's WebSocket, a check for a clean mint line, and a SQLite table that counts each signature once give you minted so far and mints per minute, with a runnable main.ts.

## Who uses it

A creator running a timed drop wants one number on the mint page: how many are gone. Holders watch it to decide whether to hurry, and the team watches it to see whether the drop is on pace. A counter that reads the chain moves the moment a mint lands, with no spreadsheet and no one refreshing an explorer.

The same number suits a membership project that caps its passes. When the counter reaches the cap, the page flips to a sold-out state on its own, and the team knows the allowlist for the next round can open.

A hackathon team needs one busy mint program to point at, a key, and a small page or terminal to show the number.

## What it counts

The counter treats one landed transaction with a mint instruction as one NFT. The mint programs behind most drops, Candy Machine and its guard program, write a log line for each instruction they run, and a clean mint carries a line that ends in `Instruction: Mint` or `Instruction: MintV2`. The code looks for that line on a transaction whose `err` is null, and the line must come from the Candy Machine program (`CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR`) itself in the same transaction. The guard program logs the same instruction names, and a mint that fails a guard check with the tax guard on can still land with `err` null and mint nothing.

| Figure | Where it comes from | Notes |
|---|---|---|
| Minted so far | rows in the `mints` table plus `START` | `START` is the number already minted before you began counting |
| Mints in the last minute | rows with a timestamp in the last 60 seconds | the pace of the drop |
| Progress | minted divided by `SUPPLY` | printed only when you set `SUPPLY` |
| Notifications seen | every message received, mints or not | shows the stream is alive on a quiet drop |

The table keys on the transaction signature. A signature that arrives a second time, for example one written again by a backfill, is a no-op. A restart reads the same file, so the total survives.

## The build

The counter is one file on Node 24 with no package beyond what Node ships. It is read-only: no private key, nothing sent.

1. Open a WebSocket to `wss://services.carbium.sh` with the key as `?api-key=`.
2. Send `logsSubscribe` with `{ mentions: [WATCH] }` at commitment `confirmed`. The first reply carries the subscription id, or an error if the subscription is refused.
3. On each `logsNotification`, skip any where `value.err` is set, then look in `value.logs` for a mint line logged by the Candy Machine program.
4. Insert the signature into SQLite with `INSERT OR IGNORE`, so a repeat changes nothing.
5. Every 10 seconds, print the total, the last minute and the number of notifications seen, and print a sold-out line once, when the total first reaches `SUPPLY`.

`WATCH` defaults to the Candy Guard program, which every guarded mint lists. For a real counter, set it to the candy machine address of your drop: every mint of that drop lists the account, and the stream then carries that drop alone.

`main.ts` (run: `CARBIUM_KEY=<YOUR_KEY> node main.ts`)

```ts
// BI0022 · Live mint progress counter
// https://carbium.sh/library/blockchainideas/live-mint-progress-counter
// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.
// SPDX-License-Identifier: MIT

import { DatabaseSync } from "node:sqlite";

const key = process.env.CARBIUM_KEY;
if (!key) {
  console.error("Set CARBIUM_KEY to your Carbium API key.");
  process.exit(1);
}
// Candy Guard by default: its mints list it. Set WATCH to one drop's candy machine address to count that drop alone.
const WATCH = process.env.WATCH ?? "Guard1JwRhJkVH6XZhzoYxeBVQe872VH6QggF4BWmS9g";
const SUPPLY = Number(process.env.SUPPLY ?? 0); // items in the drop; 0 hides the progress figure
const START = Number(process.env.START ?? 0); // items minted before this table began counting
const WS_URL = `${process.env.CARBIUM_WS_URL ?? "wss://services.carbium.sh"}/?api-key=${key}`;

const db = new DatabaseSync("mints.db");
db.exec("CREATE TABLE IF NOT EXISTS mints (signature TEXT PRIMARY KEY, at INTEGER NOT NULL)");
const insert = db.prepare("INSERT OR IGNORE INTO mints (signature, at) VALUES (?, ?)");
const since = db.prepare("SELECT COUNT(*) AS n FROM mints WHERE at > ?");
const count = (after = 0): number => Number(since.get(after)?.n ?? 0);

const CANDY_MACHINE = "CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR";
const MINT_LINE = /^Program log: Instruction: Mint(V2)?$/;
let seen = 0; // every notification, mint or not
let soldOut = false;

// True when the Candy Machine program itself logs a mint line, tracked through the invoke stack.
function minted(logs: string[]): boolean {
  const stack: string[] = [];
  for (const line of logs) {
    const invoke = /^Program (\w+) invoke \[\d+\]$/.exec(line);
    if (invoke) stack.push(invoke[1] as string);
    else if (/^Program \w+ (success|failed)/.test(line)) stack.pop();
    else if (stack.at(-1) === CANDY_MACHINE && MINT_LINE.test(line)) return true;
  }
  return false;
}

function connect(): void {
  const ws = new WebSocket(WS_URL);
  ws.onopen = () => ws.send(JSON.stringify({
    jsonrpc: "2.0", id: 1, method: "logsSubscribe",
    params: [{ mentions: [WATCH] }, { 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}` : `subscribed, id ${msg.result}`);
      return;
    }
    if (msg.method !== "logsNotification") return;
    seen++;
    const { signature, err, logs } = msg.params.result.value as { signature: string; err: unknown; logs: string[] };
    if (err !== null || !minted(logs)) return; // landed mints only
    if (insert.run(signature, Date.now()).changes > 0) console.log(`MINT ${signature} total ${START + count()}`);
  };
  ws.onclose = () => setTimeout(connect, 2000);
  ws.onerror = () => ws.close();
}

setInterval(() => {
  const n = START + count();
  const progress = SUPPLY > 0 ? ` of ${SUPPLY} (${((100 * n) / SUPPLY).toFixed(1)}%)` : "";
  console.log(`minted ${n}${progress}, last minute ${count(Date.now() - 60_000)}, ${seen} notifications seen`);
  if (SUPPLY > 0 && n >= SUPPLY && !soldOut) {
    soldOut = true;
    console.log("sold out");
  }
}, 10_000);

connect();
```

The subscription runs at `confirmed`, so a mint shows up within moments of landing and is very unlikely to be rolled back. The close handler waits two seconds and subscribes again. Notifications missed during that gap are not replayed.

## What it costs

The counter's only recurring cost is the subscription. A logs subscription that filters by mention opens at 25 credits, then costs 20 credits per MiB the server sends. It sends a notification for every transaction that lists your address, mint or not, so the bill follows the traffic on the address you watch.

A worked case: a drop that draws 50 notifications a second at about 2 KiB each sends roughly 350 MiB an hour, which is about 7,000 credits. That is 1.4% of the Free grant and 0.07% of one Dev month. Pointing `WATCH` at the candy machine instead of the program keeps the stream down to your own drop. The counter never prints a credit figure for you, so read the notification count from the status line and size the rest from your own message sizes.

| Plan | Credits | Sockets |
|---|---|---|
| Free ($0) | 500K once, at sign-up | 5 per account |
| Dev ($20) | 10M per month | set by the plan |
| Business ($250) | 50M per month | set by the plan |
| Pro ($500) | 200M per month | set by the plan |

Limits count per account, so a second tool on the same keys draws on the same budget and the same socket cap. The counter holds one socket. A refused subscription costs nothing, so a retry loop on a full socket cap spends no credits.

## What to add next

- A page: serve the total from a small HTTP endpoint and push each change to the browser with server-sent events, so the mint page shows the number without polling.
- A true starting number: read the candy machine account once with getAccountInfo, which costs 10 cells, and decode its redeemed count into `START`. The account is the chain's own total, so it also corrects any gap in your table.
- A backfill after a restart: getSignaturesForAddress lists signatures with an `err` field, and getTransaction fetches the logs for each one. Both cost 50 cells a call.
- A milestone alert: post to a channel at 25%, 50% and 90% of `SUPPLY`.
- A per-minute history: store the minute buckets and draw the pace of the drop as a chart.

The first two items are the shortest path to a counter you can put in front of holders. The [Failed-mint monitor](https://carbium.sh/library/blockchainideas/failed-mint-monitor) is the matching view for the mints that did not land, built on the same subscription.

## Where it ends

- The count is as good as the log match. A mint program that words its line differently, or a Core mint, which logs a different instruction name, adds no rows until you change the pattern.
- One transaction counts as one NFT. A transaction that mints several items in one call is counted once.
- Only mints that landed with `err` null count, and only when the Candy Machine program logs its own mint line in the same transaction. A guard program line alone adds nothing, and a transaction rejected before it ran, or one whose blockhash expired, never reaches the logs.
- A disconnect leaves a gap. Mints that land while the socket is down are missing from the table and from the total until you backfill.
- A backfill reaches back 30 days at most, because getSignaturesForAddress reads from the address index and its pages end there. An empty page past that point is the index's age limit and says nothing about older mints. For a drop older than a month, take the total from the candy machine account instead.
- The table starts at zero on first run. Set `START` for a drop already under way, or the number on screen is low.
- The counter does not check who minted or whether the buyer paid the right price. It reads the program's success line and nothing else.

## When it goes wrong

| What goes wrong | What to do |
|---|---|
| The subscribe reply is an error, or the socket closes straight away. | Check that CARBIUM_KEY holds the whole key and that the account is under its socket cap, which is 5 on Free. A refused subscription is free, so retrying costs nothing. |
| The notification count grows but the minted total stays at zero. | The stream is alive and no mint line from the Candy Machine program matched. Print a few `value.logs` arrays for one mint of your drop and adjust the pattern to the wording its program uses. |
| The total is higher than the drop's real count. | The default address is a program shared by many drops. Set WATCH to your candy machine address so only your drop is counted. |
| The total is lower than an explorer shows after a restart or a drop in the connection. | The counter misses mints that land while it is offline. Backfill with getSignaturesForAddress and getTransaction, or set START from the candy machine account. |
| Credits fall faster than the worked case. | Count the notifications on the status line against the hours run. Watching a program streams every drop on it, so switch WATCH to your own candy machine address. |
| The script fails on startup with a database error. | The file `mints.db` is written to the folder the command runs from. Run it from a folder you can write to. |

## Questions

### Why count from the logs and not from the candy machine account?

The logs push each mint as it lands, so the counter moves at once. The account holds the authoritative total but has to be polled. Use the account to set `START` and the logs for the live feel.

### Does a failed mint raise the counter?

No. The code skips every notification whose `err` is set, and it requires the Candy Machine program (`CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR`) to log its own mint line in the same transaction, so a guard check that fails after the transaction lands adds nothing. The [Failed-mint monitor](https://carbium.sh/library/blockchainideas/failed-mint-monitor) covers the others.

### Can it gate a page for people who minted?

The counter alone does not know who the holders are. The [NFT membership gate](https://carbium.sh/library/usecase/nft-membership-gate) reads a wallet's holdings and decides who gets in.

### Will this run on the Free plan?

Yes, for one drop. It holds one of the 5 sockets, and its credit use follows the notifications on the address you watch. Watching one candy machine keeps that small.

## Related

- [Failed-mint monitor](https://carbium.sh/library/blockchainideas/failed-mint-monitor) (Blockchain ideas, BI0001)
- [NFT membership gate](https://carbium.sh/library/usecase/nft-membership-gate) (Use cases, UC0012)
- [carbium.sh/docs#websocket](https://carbium.sh/docs#websocket)
- [carbium.sh/docs#limits](https://carbium.sh/docs#limits)
- [carbium.sh/docs#endpoints](https://carbium.sh/docs#endpoints)
- [carbium.sh/docs#auth](https://carbium.sh/docs#auth)
- [carbium.sh/docs#rpc](https://carbium.sh/docs#rpc)
- [carbium.sh/docs#migrate](https://carbium.sh/docs#migrate)
