---
id: HS0157
title: "Skipped-slot-safe block scan"
url: https://carbium.sh/library/howsolana/skipped-slot-safe-block-scan
collection: How to use Solana
category: History and parsing
revision: 1
updated: 2026-11-23
author: Carbium
code: MIT (LICENSE in the zip); text: all rights reserved, Carbium Corporation
---

# Skipped-slot-safe block scan

One read-only TypeScript file walks recent slots with getBlock, marks each skipped slot as a gap instead of a failure, and prints a tally. It never stops at the first gap, and it sends maxSupportedTransactionVersion 1 so v1 transactions do not break the read.

## What a skipped slot looks like

A Solana slot is a short window in which one leader may produce a block. A leader that produces nothing, or whose fork is dropped, leaves the slot without a block. Since the Alpenglow switch on 2026-10-21 a slot lasts about 200 ms, so a gap is brief, but it still breaks any loop that expects a block at every slot number.

The standard Solana JSON-RPC answer to getBlock for a skipped slot is error -32007, with a message saying the slot was skipped or is missing due to a ledger jump. A node also answers missing for a slot below its own ledger floor, even when a block was made there. The scan treats both as a gap and reads the server message to decide. Any other error, such as a timeout or a 429, stays in the failed count, so a real problem never hides as a gap. The [error reference](https://carbium.sh/docs/errors) lists the codes Carbium answers.

## Choosing the range

The scan needs a tip to count back from. `getSlot` with `finalized` gives the newest slot the network has finalized. It is one of the cheap cached reads on the [RPC page](https://carbium.sh/docs/rpc), so the tip costs one cell. Cells are the admission charge per call, and this single read costs very little.

Finalized sits 0 to 1 slots behind processed now, where it used to sit about 32 slots back, so the tip is close to the newest block. The file stops two slots short of that tip, so a block still settling at the edge is never read and counted as missing.

Every getBlock call names the `finalized` commitment as well. A block the scan prints has therefore reached finalized. @solana/kit fills in `confirmed` when a call leaves commitment out, so the file sets it in each call and does not depend on that default.

## The code

Install `@solana/kit` at 8.6.0, export `CARBIUM_KEY` and run the file with Node 24, which strips the types on load. The first argument is how many slots to scan, from 1 to 100, and it defaults to 20. The file writes nothing to disk and signs nothing.

`main.ts` (run: `node main.ts 20`)

```ts
// HS0157 · Skipped-slot-safe block scan
// https://carbium.sh/library/howsolana/skipped-slot-safe-block-scan
// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.
// SPDX-License-Identifier: MIT

import { createDefaultRpcTransport, createSolanaRpcFromTransport } 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 } }),
);

const count = Number(process.argv[2] || 20);
if (!Number.isInteger(count) || count < 1 || count > 100) {
  console.error("Usage: node main.ts [slots, 1 to 100]");
  process.exit(1);
}

type SlotArg = Parameters<typeof rpc.getBlock>[0];

// A skipped slot answers with a server message saying it was skipped or missing.
function isGap(e: unknown): boolean {
  const msg = (e as { context?: { __serverMessage?: unknown } }).context?.__serverMessage;
  return typeof msg === "string" && /skipped|missing/i.test(msg);
}

const tip = await rpc.getSlot({ commitment: "finalized" }).send();
const first = tip - BigInt(count) - 2n;
const last = first + BigInt(count);
console.log(`scanning ${first} to ${last - 1n}, finalized tip ${tip}`);

const tally = { blocks: 0, skipped: 0, failed: 0 };
for (let s = first; s < last; s += 1n) {
  try {
    const block = await rpc.getBlock(s as SlotArg, {
      commitment: "finalized",
      maxSupportedTransactionVersion: 1,
      transactionDetails: "none",
      rewards: false,
    }).send();
    if (block === null) {
      tally.skipped++;
      console.log(`${s} no block`);
      continue;
    }
    tally.blocks++;
    console.log(`${s} blockhash=${block.blockhash} parent=${block.parentSlot} time=${block.blockTime}`);
  } catch (e) {
    if (isGap(e)) {
      tally.skipped++;
      console.log(`${s} skipped`);
    } else {
      tally.failed++;
      console.log(`${s} failed: ${e instanceof Error ? e.message : String(e)}`);
    }
  }
}
console.log(`blocks=${tally.blocks} skipped=${tally.skipped} failed=${tally.failed}`);
```

The transport is built once, so one client and its open connection serve the whole run. Each getBlock passes `maxSupportedTransactionVersion` set to 1. Mainnet carries v1 transactions, and an absent value or 0 answers -32015 for a block that holds one, so the option stays in every call. `transactionDetails` is set to none, which keeps each reply to the hash, the parent and the time, the only fields the scan prints.

The calls run one after another. A failed slot prints its message and the loop moves on to the next slot, so a single 429 does not end the scan. The tally at the end gives the three counts.

## Reading the tally

| Answer | Meaning | What the scan counts |
|---|---|---|
| A block with a blockhash | The slot was produced and the node holds its block. | blocks |
| Error with a skipped or missing message | The slot has no block on this node. | skipped |
| null | The node reports no block for the slot. | skipped |
| -32015 | A block holds a v1 transaction and the version option was not sent. | failed |
| 429 with a retry-after hint | The key went over its rate for this call. | failed |

A quiet range usually shows a skipped count of zero or one. The failed count is the number to act on, because it is the only one that means a call did not complete.

> The skipped count describes the leaders and forks of that range. It says nothing about your code, so do not retry a gap to make it go away.

## On Carbium

Carbium serves Solana mainnet on one domain, services.carbium.sh, under one key. This file reads only its RPC address, `https://services.carbium.sh`. The [endpoint list](https://carbium.sh/docs/endpoints) gives the address for each service. The key goes in the `x-api-key` header, as the [auth page](https://carbium.sh/docs/auth) describes, and the file sends nothing else with it.

Connections stay open for 600 s and TLS sessions resume, so one client carries every call in the run. A JSON-RPC batch takes up to 100 calls in one POST with no added envelope. A longer scan could batch its getBlock calls that way. This file keeps one call at a time so the output reads in slot order.

A call over its req/s limit waits once and is served if its cells refill within 1 s. Past that it gets 429 with a retry-after hint. Limits are per account, and the keys of one account share one budget, so a second script on the same key slows the first. The [limits page](https://carbium.sh/docs/limits) gives the rate for each plan.

## Where it ends

The scan tells a gap from a fault by the server message. A node that words that message differently moves its gaps into the failed count. Read the failed lines before you trust the tally.

A missing answer for an old slot does not prove a skip. A node drops old ledger data, so a slot below its floor can answer missing even though a leader made a block there. This scan reaches only the range you ask for, at most 100 slots back from the finalized tip, and it does not walk history. It keeps no record between runs, so a monitor that needs one has to write its own store.

The file reads blocks only. It cannot say why a slot was skipped, whether the leader was offline, or whether a fork was dropped. Those answers need data that a getBlock call does not return.

## When it goes wrong

| What goes wrong | What to do |
|---|---|
| Every slot prints failed with an error about -32015 and a transaction version. | The getBlock call lacks maxSupportedTransactionVersion set to 1. Keep that option in the call. An absent value or 0 answers -32015 for a block that holds a v1 transaction. |
| Lines show 429, and the failed count grows with each run. | Lower the count argument, or wait for the retry-after seconds and run again. The [limits page](https://carbium.sh/docs/limits) gives the rate for your plan, and a second script on the same key shares that budget. |
| The run stops at once with a message about CARBIUM_KEY. | Export CARBIUM_KEY in the shell that runs the file. The key comes from the environment and never from an argument, so it stays out of shell history. |
| The skipped count is high on a range you know was busy. | Check the range. An old range can reach below the node's ledger floor, which answers as missing. Scan a recent range and compare the tally with the blocks you expected. |
| Every row fails with an error about the slot argument. | The slot is a bigint. If you edit the loop, keep the arithmetic in bigint and do not mix it with a plain number. |

## Questions

### Why does the scan not stop at the first missing slot?

A gap is normal on a live chain, and one skipped slot says little about the next. Counting the gaps and moving on gives the full range in one run.

### Does a skipped slot mean the leader missed its turn?

Often, but getBlock cannot tell you why. A dropped fork can also leave a slot without the block the node kept, and the file counts both the same way.

### Which commitment should a scan use?

This file uses finalized, so each block it prints has reached finalized. Use processed only when a fresher read matters more than a later correction.

### Can I scan a range from last week?

Only within what the node still holds. A gap in an old range may be the ledger floor, so treat it as missing data and not as a skipped slot.

## Related

- [Transaction version error -32015](https://carbium.sh/library/howsolana/transaction-version-error-32015) (How to use Solana, HS0012)
- [RPC rate-limit alerts](https://carbium.sh/library/usecase/rpc-rate-limit-alerts) (Use cases, UC0001)
- [carbium.sh/docs/endpoints](https://carbium.sh/docs/endpoints)
- [carbium.sh/docs/auth](https://carbium.sh/docs/auth)
- [carbium.sh/docs/limits](https://carbium.sh/docs/limits)
- [carbium.sh/docs/errors](https://carbium.sh/docs/errors)
- [carbium.sh/docs/rpc](https://carbium.sh/docs/rpc)
