Withdrawal confirmation tracker
Poll a whole queue of withdrawal signatures in one call, see which are landing, finalized, failed or expired, and treat block height as the only signal that a rebuilt transaction cannot pay a customer twice.
Seven states for a withdrawal
A withdrawal queue holds rows in different places at once: signed and sent, seen at processed, confirmed, finalized, failed, or lost. The tracker reads the chain for all of them together and prints one line per signature with a state, the slot and the error, then a tally. Each row is a signature and, when you have it, the lastValidBlockHeight that getLatestBlockhash returned when the transaction was built.
| State | What the poll saw | What the operator does |
|---|---|---|
| in flight | No status yet, and the chain is still below the expiry height | Keep polling. Resending the same signed bytes is safe. |
| landing | Processed or confirmed, no error | Wait for finalized. |
| finalized | Finalized, no error | Close the withdrawal in the ledger. |
| failed | The status carries an error | Wait for finalized, then read the error before any retry. |
| expired | No status, and the finalized height is past the expiry height | Safe to build a new transaction for the same payout. |
| unseen | No status, and no expiry height to judge by | Hold. Never resend on a guess. |
| unread | The status call itself failed | Run the pass again. |
Two states carry the weight. finalized lets the ledger close the withdrawal, and expired is the only state that allows a second transaction for the same payout. Everything else means wait, or look at the row yourself.
One call for the whole queue
getSignatureStatuses takes up to 256 signatures and answers with one entry for each, in order: a status object, or null when the node knows nothing about that signature. Passing searchTransactionHistory: true makes the node look past its recent status cache, so a withdrawal sent hours ago still resolves. A status carries the slot, the confirmationStatus and err. The call takes no commitment argument, because each entry reports the highest level its signature has reached.
The height read runs first and names finalized in the call, since @solana/kit fills in confirmed when a call leaves commitment out. The order matters. A block height that is already past lastValidBlockHeight on the finalized chain means the blockhash can never be used again, so a null status read afterwards is final. If the status read ran first, a transaction could land between the two calls and a paid withdrawal would read as expired.
// UC0063 · Withdrawal confirmation tracker// https://carbium.sh/library/usecase/withdrawal-confirmation-tracker// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MIT// Read-only: one batched status read for a queue of withdrawal signatures, with expiry judged by block height.import { address, createDefaultRpcTransport, createSolanaRpcFromTransport, 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); }const rpc = createSolanaRpcFromTransport(createDefaultRpcTransport({ url: process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh", headers: { "x-api-key": key } }));type W = { sig: string; lastValid?: bigint };type St = { slot: bigint; err: unknown; confirmationStatus: string | null } | null;const big = (_k: string, v: unknown) => (typeof v === "bigint" ? v.toString() : v);const msg = (e: unknown) => (e instanceof Error ? e.message : String(e));// "signature[,lastValidBlockHeight]", the height that getLatestBlockhash returned when the transaction was builtfunction parse(a: string): W { const [sig, lv] = a.split(","); signature(sig!); // throws on a malformed signature return { sig: sig!, lastValid: lv ? BigInt(lv) : undefined };}// No argument: the 10 newest signatures of the USDC mint, listed at confirmed; finalized trails by 0 to 1 slots, so a landing row shows only now and thenasync function demo(): Promise<W[]> { const mint = address("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"); const page = await rpc.getSignaturesForAddress(mint, { limit: 10, commitment: "confirmed" }).send(); return page.map((s) => ({ sig: s.signature }));}function classify(w: W, st: St | undefined, h: bigint | undefined): string { if (st === undefined) return "unread"; // the status call failed if (st) return st.err ? "failed" : st.confirmationStatus === "finalized" ? "finalized" : "landing"; if (w.lastValid === undefined || h === undefined) return "unseen"; // nothing to judge expiry by return h > w.lastValid ? "expired" : "in flight";}const args = process.argv.slice(2);const list = args.length ? args.map(parse) : await demo();// Height first: once the finalized height is past the expiry height, a null status read after it is final.let height: bigint | undefined;const statuses: (St | undefined)[] = [];try { height = await rpc.getBlockHeight({ commitment: "finalized" }).send(); }catch (e) { console.log(`getBlockHeight failed: ${msg(e)}`); }// One status call takes up to 256 signatures: a chunk that fails leaves its rows unread, the others still report.for (let i = 0; i < list.length; i += 256) { const chunk = list.slice(i, i + 256); try { const res = await rpc.getSignatureStatuses(chunk.map((w) => signature(w.sig)), { searchTransactionHistory: true }).send(); statuses.push(...res.value); } catch (e) { console.log(`getSignatureStatuses failed: ${msg(e)}`); statuses.push(...chunk.map(() => undefined)); }}const tally: Record<string, number> = {};list.forEach((w, i) => { const st = statuses[i]; const state = classify(w, st, height); tally[state] = (tally[state] ?? 0) + 1; const left = w.lastValid !== undefined && height !== undefined ? String(w.lastValid - height) : "-"; console.log(`${w.sig.slice(0, 16)} ${state.padEnd(9)} slot=${st?.slot ?? "-"} level=${st?.confirmationStatus ?? "-"} blocks-left=${left} err=${st?.err ? JSON.stringify(st.err, big) : "-"}`);});console.log(`height=${height ?? "-"} tally=${JSON.stringify(tally)}`);
run: CARBIUM_KEY=$CARBIUM_KEY node main.ts [<signature>[,<lastValidBlockHeight>] ...]
Arguments are signature[,lastValidBlockHeight], one per withdrawal. With none, the script takes the 10 newest signatures of the USDC mint at confirmed commitment, so a first run shows finalized and failed rows, and a landing row only now and then. Those carry no expiry height, so any row the node does not know prints unseen. The height read sits in its own try, and so does each status call. If the height read fails, every unknown row stays unseen; if a status call fails, every row in that chunk prints unread; the message names the call.
The queue itself belongs in your database: the signature, the lastValidBlockHeight, the destination and the amount, written before the transaction is sent. The script keeps no state and works from whatever rows you hand it. Rows that reach finalized drop out of the next pass.
Expiry by block height is the resend signal
A transaction names a recent blockhash, and that blockhash stops being accepted once the chain passes the lastValidBlockHeight returned with it. Before that height the transaction can still land, on any leader, at any moment, including after you decided it was lost. A timer of 30 seconds or 2 minutes says nothing about that: the signed bytes may be sitting in a leader's queue.
That gives two kinds of resend. Sending the same signed bytes again is always safe before expiry, because the signature is the same and the chain executes it once. Building a new transaction, with a new blockhash and so a new signature, is a second payment if the first one lands later. So the new transaction waits for expired: no status for the old signature, and a finalized block height above its lastValidBlockHeight.
Block height and slot are different counters. Slots the leader never produced do not add a block, so height grows a little slower than the slot number. Always compare height with height, and store the one number getLatestBlockhash gives you.
Keep every signature a withdrawal has ever had on its row. After a rebuild the payout has two signatures, and either one may be the one that finalized. Poll them all, and close the withdrawal on the first that finalizes. A withdrawal with a second attempt in flight is not expired until each signature on its row is.
Landed, charged and failed
A status with an err means the transaction was in a block and its instructions did not complete. The fee was spent and the signature is used, but nothing moved. The error is an object such as an instruction index with a custom code, and it can hold bigint values, so the script prints it through a replacer that turns them into strings.
Wait for finalized before acting on it. A failure seen at confirmed sits on a fork that can still be dropped, and the same signature can then land again on another fork with a different result. After finalized, the failed attempt is closed for good and a new transaction with a fresh blockhash is allowed.
Read the error before the retry loop does. A closed destination token account, a frozen account or too little balance in the hot wallet fails the same way every time, and each attempt costs a fee. Put those on a human queue and retry only the errors your own policy names as transient.
Close the ledger entry at finalized
The ledger entry for a completed withdrawal waits for finalized. Since the Alpenglow switch on mainnet, finalized sits 0 to 1 slots behind processed, where it used to trail by about 32, and a slot lasts about 200 ms. Waiting for it costs about a slot, so there is little reason to book a payout earlier. What a customer sees at confirmed, such as a pending notice with the signature, is a message decision and stays separate from the ledger.
For one signature you hold, signatureSubscribe sends a single confirmation and then ends, which suits a withdrawal screen. A batch pass suits the reconciliation job that sweeps the open queue and decides about expiry, since a subscription says nothing about a transaction that never lands. The Dropped transaction detector covers that one signature in more detail, and Bulk payout preflight check covers the checks before the send.
Where it ends
- The tracker reads and prints. It signs nothing, sends nothing and resends nothing, so the resend itself stays in your sender.
- A transaction built on a durable nonce has no block-height expiry. The expired state does not apply to it, and its rows stay unseen.
- A null status for a very old signature is not proof that it never landed. The node answers for what its ledger holds, so judge expiry only on recent withdrawals with a stored expiry height.
- The demo path lists signatures from Carbium's address index, which keeps up to 30 days. A busy mint fills the newest page, so the demo never reaches that edge.
- finalized means the transfer is final on chain. It does not say the destination is the address your customer meant, or that your exchange's compliance checks passed, and it does not read the amount.
When it goes wrong
| what goes wrong | what to do |
|---|---|
| Every row prints unread. | The status call failed and the message above the rows names why. A rate-limited call carries a retry-after hint, and the next pass retries the whole batch. Rows stay as they were, so nothing is resent. |
| A row stays in flight for a long time. | The chain has not passed its expiry height yet. Keep polling. A second transaction before that height can pay the customer twice. |
| A row reads expired but the customer says the money arrived. | The payout probably has another signature from an earlier rebuild. Poll every signature kept on the row, and close the withdrawal on whichever one finalized. |
| Rows print unseen with no signature that landed. | No expiry height was stored with the row, or the height read failed. Store lastValidBlockHeight at signing time, and treat unseen as hold until it exists. |
| A finalized failure repeats on every retry. | The cause sits in the destination or the source balance. Read the error, fix the account, and retry once. |
Questions
Can we resend the same signed transaction before it expires?
Yes. The signature is the same, so the chain runs it at most once. The risk starts when you sign again with a new blockhash, which is why a new transaction waits for expiry by height.
Why read the block height at finalized?
At finalized, a height above lastValidBlockHeight means any block that could have carried the transaction is already on the finalized chain or dropped. A null status after that read is a safe signal.
Do we need a dedicated node for this job?
No. A pass is one status call and one height read over HTTPS at services.carbium.sh, under a plan key whose limits all keys of the account share. Carbium sells the Free, Dev, Business and Pro plans.
How many withdrawals can one pass check?
A status call takes up to 256 signatures, and the script sends a longer queue in chunks of 256 with a try around each. A chunk that fails shows as unread while the others still report.