library / How to use Solana / Webhooks / HS0126
Missed webhook backfill
A logsSubscribe socket sends only while it is open, so a disconnect leaves a gap. One read-only TypeScript file pages getSignaturesForAddress back to your stored mark and reads each transaction with getTransaction.
Why a socket misses logs
A logsSubscribe subscription with a mentions filter pushes a notification for each transaction whose logs name the address. It does so only while the socket is open and the subscription is live. Nothing in the protocol keeps a copy for a client that was away. If the socket closes, the process restarts, or the subscribe call lands after the transaction, that transaction produces no notification at all. A socket that reconnects therefore has a gap, and the notifications for that gap never arrive on their own. For the reconnect side of this, see WebSocket keepalive and reconnect.
Solana's PubSub methods send only what happens after the subscribe call, so a reconnect cannot ask for the missed part through the same socket. The gap has to be filled over HTTPS with RPC. Remember which transaction you finished last for each address, then read the newer ones from RPC once the socket is back. The socket keeps the live feed, and RPC answers for the gap.
Carbium's socket is wss://services.carbium.sh, and its RPC is https://services.carbium.sh, both listed under endpoints. The socket takes the key as ?api-key= in its URL. RPC calls take it in the x-api-key header. A mentions filter names one address per subscription, so a tracked list needs one subscription per address, or one backfill per address run from the same stored marks. A plain SOL wallet is a good case for this pattern. Its account state is not streamed, so it is watched with logsSubscribe mentions and read with getBalance.
The mark and the backfill
Store one signature per address: the newest one your handler has finished. This is the mark. After a reconnect, getSignaturesForAddress pages back from the chain head with until set to the mark, so the walk stops at the signature you already have. The list comes back newest first. Each signature in the gap is then read with getTransaction, and the reads are handled oldest first so your state moves in the order the chain wrote them.
Two calls do the work. The table gives the cost of each and the commitment this entry sets. Both calls pass commitment: "confirmed" explicitly. @solana/kit 8.6.0 fills in confirmed when a call leaves commitment out, but the entry states the level in its own calls so the reader can see which one is in use.
| Call | Used for | Cost | Commitment |
|---|---|---|---|
| getSignaturesForAddress | List the gap, newest first, back to the mark | 50 cells | confirmed |
| getTransaction | Read each listed transaction in order | 50 cells | confirmed |
Save the mark only after the handler has finished every transaction in the gap. A mark moved too early turns a crash in the middle of the gap into a silent hole. Keep the mark in storage that survives a restart. The example writes nothing itself, so it prints the next mark for you to save.
The code
Install @solana/kit at 8.6.0 and export CARBIUM_KEY. Run the file with Node 24, which strips the types on its own. The first argument is the address and the second is the mark you stored. With no mark the run lists the newest three signatures, so it shows output on any address.
// HS0126 · Missed webhook backfill// https://carbium.sh/library/howsolana/missed-webhook-backfill// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MITimport { address, createDefaultRpcTransport, createSolanaRpcFromTransport, 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);}const url = process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh";const rpc = createSolanaRpcFromTransport( createDefaultRpcTransport({ url, headers: { "x-api-key": key } }),);// Usage: node main.ts <address> [mark]. The mark is the last signature you handled.// With no mark, the run lists the newest 3 signatures, so it works on any address.const [addr, markArg] = process.argv.slice(2);if (!addr) { console.error("Usage: node main.ts <address> [mark-signature]"); process.exit(1);}const target = address(addr);const mark = markArg as Signature | undefined;const cap = mark ? 500 : 3;let clean = true;// Newest first. Page back until the mark (until excludes it), the cap, or the end of the index.const gap: Signature[] = [];let before: Signature | undefined;while (gap.length < cap) { const limit = Math.min(100, cap - gap.length); const page = await rpc .getSignaturesForAddress(target, { limit, before, until: mark, commitment: "confirmed" }) .send() .catch((e: unknown) => { clean = false; console.log(`signature page error: ${e instanceof Error ? e.message : String(e)}`); return null; }); if (page === null) break; for (const s of page) gap.push(s.signature); if (page.length < limit) break; before = page[page.length - 1].signature;}// A capped walk that never reached the mark leaves older signatures unread.if (mark && gap.length >= cap) clean = false;console.log(`gap: ${gap.length} signatures since ${mark ?? "the newest three"}`);// Oldest first, so the handler sees them in order.const oldestFirst = [...gap].reverse();const reads = await Promise.allSettled( oldestFirst.map((sig) => rpc .getTransaction(sig, { commitment: "confirmed", encoding: "json", maxSupportedTransactionVersion: 1, }) .send(), ),);reads.forEach((r, i) => { const sig = oldestFirst[i]; if (r.status === "rejected") { clean = false; console.log(`${sig} error: ${r.reason instanceof Error ? r.reason.message : String(r.reason)}`); } else if (r.value === null) { console.log(`${sig} null: no transaction the node can serve`); } else { console.log(`${sig} slot ${r.value.slot}`); }});const next = gap[0];console.log( next && clean ? `store as next mark: ${next}` : "keep the old mark: an error line appeared or the gap is empty",);
run: node main.ts JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4
The transport sends both kinds of call to the RPC endpoint with the key in the x-api-key header. The loop pages with before and stops when a page comes back shorter than its limit, which means until reached the mark or the index ran out. A page that fails is printed as an error and leaves the run unclean, so the mark stays where it was. A walk that hits the cap before it reaches the mark is treated the same way, because the signatures past the cap are still unread. The reads run through Promise.allSettled, so one failed call does not hide the others. The example address is Jupiter's aggregator program, which sees steady traffic, so its newest signatures are there to read at once.
Reading the output
Each line is a signature with one of three results. Read them in this order.
- slot N: the transaction was read. Pass it to your handler.
- null: the signature is listed but the node returns no transaction for it. Log it and move on. This is expected for older signatures.
- error: the read failed. Keep the old mark, so the next run reads the gap again.
The last line gives the mark to store. It is valid only when no error line appeared and the walk reached the mark or the end of the index. An error line means one signature in the gap was not handled, so moving the mark to the newest signature would skip it. The example prints the old mark in that case, and the next run starts from the same place.
What a backfill costs
Free carries 5 WebSocket sockets per account. A logsSubscribe with a mention costs 25 credits to open, then 20 credits per MiB the socket sends, as the rate limits page sets out. A busy address sends more notifications than a quiet one, so the per-MiB charge is the part that grows with traffic. The backfill is RPC work, so it draws on the account's credits too.
Rates matter more than credits for a long gap. getSignaturesForAddress runs at 0.24 calls per second on Free, 1.2 on Dev, 100 on Business and 500 on Pro. A gap of 1,000 signatures at a limit of 100 takes ten calls. On Free that is about 42 seconds of calls spaced by the rate, and on Pro it is a fraction of a second.
A call over its rate waits once if its cells refill within one second. Past that it gets a 429 with a retry-after hint. The example does not retry on its own. A 429 on a signature page or a transaction read becomes an error line, the mark stays where it was, and the next run reads the same gap again after the wait.
Where it ends
The backfill is only as deep as the address index. getSignaturesForAddress pages come from an index that keeps up to 30 days. Past 30 days an empty page marks the index's age limit, and the address may still have older transactions. A gap that opened more than 30 days ago cannot be filled by this method. Treat an empty backfill past that age as unknown. Do not record it as complete.
A listed signature can still answer null. The index reaches below the validator's ledger floor, so getTransaction can return null for an older signature it lists. The example logs that as a line and keeps going, so one old entry does not stop the run. Handle null as a known gap in your records.
The backfill reads what the address index holds, so a transaction is in the gap only if the index lists it for the address. A signature seen at processed can still be dropped with its fork, which is why the mark waits for confirmed. The mark is not a finality proof for your ledger, and a deposit that must not be reversed still needs a check at a deeper level.
Mainnet carries v1 transactions. With maxSupportedTransactionVersion absent or 0, getTransaction answers -32015 for a v1 transaction. The example sets 1 for that reason, and a v1 transaction read without the setting shows as an error line, not as a missing one.
When it goes wrong
| what goes wrong | what to do |
|---|---|
| The backfill returns an empty list for a mark you know is old. | Check the mark's age. Past 30 days the address index has no pages for that gap. Take a new mark from the newest signature, and record the gap as unfilled for whoever reads the feed. |
| An error line with -32015 for a signature in the gap. | Set maxSupportedTransactionVersion: 1 on getTransaction. Without it, a v1 transaction answers -32015. |
| A 429 with a retry-after hint on the signature pages. | Wait for the seconds in the header, then run again with the same mark. On Free, getSignaturesForAddress runs at 0.24 calls per second, so run long gaps from a plan with more calls per second. |
| The same transaction is handled twice after a crash. | Key your handler on the signature and skip any signature your store already has. A rerun from an old mark can read a signature you handled before the crash. |
| The mark moved past a failed read, and a transaction never reached the handler. | Move the mark only when no error line appears. Keep the old mark and run again, so the failed signature is read on the next pass. |
Questions
Can a logsSubscribe socket miss logs for an address I track?
Yes. Notifications are pushed only while the socket is open and the subscription is live. A disconnect leaves a gap, and the socket does not fill that gap by itself.
Does the subscription replay the logs my socket missed?
No. Solana's PubSub sends only what happens after the subscribe call. The example fills the gap over RPC by reading the address index from the last signature you stored.
How far back can the backfill go?
The address index keeps up to 30 days. Older signatures are not listed, and an empty page past 30 days marks the index's age limit.
Which commitment should the mark use?
Use confirmed. The mark moves only after the handler finishes, and a signature seen at processed can still be dropped with its fork.
Does the backfill need a socket?
No. It is RPC over HTTPS with the key in the x-api-key header, so it can run in a cron job or on restart.