library / Blockchain ideas / BI0001
Failed-mint monitor
Yes, without a node of your own. One logsSubscribe on Carbium's hosted WebSocket, a check on err, and getTransaction on a sample give you a board of failed mints with their program logs and a count per error.
Who uses it
Two groups want the same screen. The first is the drop's own team during a mint. When failures climb, they need to know whether the cause is a sold-out supply, a guard rejecting wallets or a broken config. The board answers with a count per error code and the program's own log lines.
The second is a launchpad support desk. A user sends the signature of a mint that failed in their wallet. The agent finds it on the board, reads the error and the last log lines, and replies with the actual reason.
A hackathon crew can demo it against any busy drop, because the Candy Machine program is public and carries mints from many collections. The stream and the lookups both come from services.carbium.sh with one key.
What it shows
Each failed mint is one row. All columns except the last come from the log notification, so every failure has them.
| Column | Where it comes from | Example |
|---|---|---|
| Failed signature | value.signature in the logsNotification | the transaction id you paste into an explorer |
| Error | value.err | {"InstructionError":[2,{"Custom":6001}]} |
| Last log lines | the lines of value.logs that contain error or fail, last three | the program's own message and failed: custom program error: 0x1771 |
| Failures per minute by error | counted in the monitor, keyed by the inner error | {"Custom":6001} 14 this minute, 212 in total |
| Fee payer and compute units | getTransaction on a sampled signature | the wallet that paid and the units the failed run used |
The error key drops the instruction index and keeps the inner error, so one custom error is one bucket whichever instruction raised it. The code is decimal in err and hex in the log line (6001 is 0x1771), which matters when a support agent searches for it.
The build
The monitor is one file that needs @solana/kit and what Node 24 ships. It is read-only: no private key, nothing sent.
- Open one WebSocket to wss://services.carbium.sh with the key as ?api-key=.
- Send logsSubscribe with { mentions: [PROGRAM_ID] } at confirmed commitment. The first reply carries the subscription id, or an error if the subscription is refused (a refusal is free).
- On every logsNotification, drop those where value.err is null. logsSubscribe filters by all or by mention, so successes arrive too.
- For each failure, count it under its error, print the signature, the error and the last error log lines, and queue the signature.
- Every 5 seconds, take one signature off the queue and call getTransaction over https://services.carbium.sh. Print the fee payer and compute units. On a 429, read retry-after, requeue the signature and pause.
- Every minute, print the per-error tally for that minute and the running total, plus the MiB received so far and the subscription credits that implies.
PROGRAM_ID defaults to Candy Machine Core v3. For one drop, set it to that drop's candy machine address: every mint for the drop lists that account, and you stop paying for other collections on the program.
// BI0001 · Failed-mint monitor// https://carbium.sh/library/blockchainideas/failed-mint-monitor// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MITimport { createDefaultRpcTransport, createSolanaRpcFromTransport, isSolanaError } from "@solana/kit";import { SOLANA_ERROR__RPC__TRANSPORT_HTTP_ERROR, type Signature } from "@solana/kit";const key = process.env.CARBIUM_KEY;if (!key) { console.error("Set CARBIUM_KEY to your Carbium API key."); process.exit(1);}// Candy Machine Core v3 by default; any address your mints mention works, such as one drop's candy machine.const PROGRAM_ID = process.env.PROGRAM_ID ?? "CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR";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 GAP_MS = 5000; // one getTransaction per 5 s stays under Free's 0.24 req/sconst total = new Map<string, number>();let minute = new Map<string, number>();const queue: string[] = [];let bytes = 0;let pausedUntil = 0;const bump = (m: Map<string, number>, k: string) => m.set(k, (m.get(k) ?? 0) + 1);// {InstructionError: [ix, {Custom: 6001}]} becomes {"Custom":6001}; other errors as they come.const errorKey = (err: unknown): string => JSON.stringify(typeof err === "object" && err !== null && "InstructionError" in err ? (err.InstructionError as unknown[])[1] : err);function connect(): void { const ws = new WebSocket(WS_URL); ws.onopen = () => ws.send(JSON.stringify({ jsonrpc: "2.0", id: 1, method: "logsSubscribe", params: [{ mentions: [PROGRAM_ID] }, { commitment: "confirmed" }], })); ws.onmessage = (ev) => { const text = String(ev.data); bytes += Buffer.byteLength(text); const msg = JSON.parse(text); if (msg.id === 1) { console.log(msg.error ? `subscribe refused: ${msg.error.message}` : `subscribed, id ${msg.result}`); return; } if (msg.method !== "logsNotification") return; const { signature, err, logs } = msg.params.result.value as { signature: string; err: unknown; logs: string[] }; if (err === null) return; // the stream carries every mention; keep failures only bump(total, errorKey(err)); bump(minute, errorKey(err)); if (queue.length < 50) queue.push(signature); console.log(`FAILED ${signature} ${JSON.stringify(err)}`); for (const line of logs.filter((l) => /error|fail/i.test(l)).slice(-3)) console.log(` ${line}`); }; ws.onclose = () => setTimeout(connect, 2000); ws.onerror = () => ws.close();}setInterval(async () => { const sig = Date.now() < pausedUntil ? undefined : queue.shift(); if (!sig) return; try { const tx = await rpc .getTransaction(sig as Signature, { commitment: "confirmed", encoding: "json", maxSupportedTransactionVersion: 1 }) .send(); if (tx) console.log(` ${sig.slice(0, 8)} payer ${tx.transaction.message.accountKeys[0]} compute units ${tx.meta?.computeUnitsConsumed}`); } catch (e) { if (isSolanaError(e, SOLANA_ERROR__RPC__TRANSPORT_HTTP_ERROR) && e.context.statusCode === 429) { queue.unshift(sig); pausedUntil = Date.now() + Number(e.context.headers.get("retry-after") ?? 5) * 1000; } else console.error("getTransaction failed:", e instanceof Error ? e.message : e); }}, GAP_MS);setInterval(() => { const mib = bytes / 2 ** 20; console.log(`--- last minute ${JSON.stringify(Object.fromEntries(minute))}, total ${JSON.stringify(Object.fromEntries(total))}`); console.log(`--- received ${mib.toFixed(2)} MiB, about ${(25 + 20 * mib).toFixed(0)} subscription credits`); minute = new Map();}, 60_000);connect();
run: CARBIUM_KEY=<YOUR_KEY> node main.ts
getTransaction runs at confirmed commitment, the same level as the stream. The queue holds 50 signatures and drops new ones when full, so enrichment is a sample while counts and log lines cover every failure. The close handler reconnects and subscribes again.
What it costs
The subscription is billed in credits: a logs-mentions subscription opens at 25 credits, then costs 20 credits per MiB sent. The credit figures below are the subscription's share only. getTransaction costs 50 cells, and each plan allows it at the rate in the table.
Credits follow every notification that mentions your address, successful or not. Assume 2 KiB per notification (the monitor prints the real MiB total) and a busy mint at 100 mentions per second. That is about 703 MiB in an hour, or about 14,000 credits for the subscription.
| Plan | Credits | getTransaction rate | Subscription credits, one hour at 100 mentions/s |
|---|---|---|---|
| Free ($0) | 500K once, at sign-up | 0.24 req/s | about 2.8% of the grant |
| Dev ($20) | 10M per month | 1.2 req/s | about 0.14% of the month |
| Business ($250) | 50M per month | 5 req/s | about 0.03% of the month |
| Pro ($500) | 200M per month | 25 req/s | about 0.007% of the month |
On Free, one call every 5 seconds is 0.2 req/s, under the 0.24 limit, so the board enriches 12 failures a minute and counts the rest. On Dev a 1-second gap fits. Limits are per account, so other tools on the same keys draw on the same budget. Free carries 5 sockets and the monitor uses one.
What to add next
- A web page: serve the tally and the last 200 failure rows from a small HTTP server and push updates to the browser with server-sent events.
- Per-wallet retry counts: key a second map on the fee payer from getTransaction. This needs enrichment for every failure, so it fits Dev and above.
- An alert: post to a channel when one error passes a threshold in a minute, with its top log line.
- A restart backfill: getSignaturesForAddress returns an err field per signature, so a restart can fill the gap since the last tally.
Where it ends
- logsSubscribe takes one mention per subscription. To watch a candy machine and its guard program, open two subscriptions at 25 credits each and de-duplicate by signature, since a transaction that mentions both arrives twice.
- There is no failed-only filter, so the credits cover successful mints as well.
- Only transactions that landed produce logs. A transaction rejected in preflight, or one whose blockhash expired, does not appear.
- A Candy Guard set to charge a penalty fee instead of failing lands the rejected mint as a success with err null, so the board does not show those rejections.
- History is the 30-day address index at most. A backfill reaches no further back, and an empty page past that is the index's age limit and says nothing about the address's first transaction.
- The board has no asset metadata lookup. It names the mint program, the signature and the signer, and it cannot show the NFT image or traits.
When it goes wrong
| what goes wrong | what to do |
|---|---|
| The subscribe reply is an error, or the socket closes straight away. | Check CARBIUM_KEY and that the account is under its socket cap (Free carries 5). A refused subscription is free, so a refused retry costs nothing. |
| getTransaction returns null for a signature the stream announced. | Ask at confirmed commitment, as the code does. If it is still null, push the signature back once and try later. |
| getTransaction answers 429. | Wait the retry-after seconds the code reads, then retry. If it repeats, widen the gap to your plan's rate (0.24 req/s on Free) and check what else on the account is calling, because the limit is shared across its keys. |
| The same failure is counted twice. | A transaction that mentions two watched addresses arrives once per subscription. Keep a Set of the last few thousand signatures and skip repeats. |
| Credits fall faster than the numbers above. | Read the MiB line. Mentioning a program id streams every drop on that program, successes included. Mention the drop's candy machine address instead. |
| Nothing prints. | Either no mint failed or the address is quiet. If the MiB total grows while no failure prints, the stream works and the mints are landing. Try the default program id to see failures from other drops. |
Questions
Can I make logsSubscribe send only the failed transactions?
No. It streams logs for all transactions or for those that mention an address, so the check on err runs in your code. That is why successful notifications count toward the credits too.
Do I need my own RPC node to see program logs?
No. The logs arrive in the notification, and the full transaction comes from getTransaction. Both are served from services.carbium.sh with one key, on the WebSocket and the HTTPS endpoint.
Can the board show which NFT a failed mint was for?
It shows the mint program, the signature and the fee payer. A failed mint created no NFT, and image or trait lookups are outside this board.
Will this run on the Free plan?
Yes. At 100 mentions per second the subscription uses about 14,000 credits an hour, so the 500K credits cover about 35 hours of the stream alone. The queue keeps getTransaction under 0.24 req/s, and enrichment is a sample there; counts and logs are complete.
How do I turn a custom error code into a name?
The log lines usually carry the program's message. For the rest, look the number up in the program's published error table. The monitor keeps the number as the key so the lookup is yours to add.