---
id: HS0029
title: "Consistent reads with minContextSlot"
url: https://carbium.sh/library/howsolana/consistent-reads-with-mincontextslot
collection: How to use Solana
category: Confirmation and retries
revision: 1
updated: 2026-11-22
author: Carbium
code: MIT (LICENSE in the zip); text: all rights reserved, Carbium Corporation
---

# Consistent reads with minContextSlot

One TypeScript file takes the slot of a first read as a floor, then reads an account with minContextSlot so no node answers from an older view. It retries timeouts, 429s and stale-node refusals, each on its own schedule, and stops on other errors.

## Why two reads disagree

A production RPC endpoint is rarely one machine. Requests spread across several nodes, and each node sits at a slightly different point in the chain. Read the latest blockhash from one node and an account from another, and the account can come from a view older than the blockhash you already hold. The app then sees a balance that predates a transfer it just confirmed, or a latest-block answer that moves backwards between two polls.

A commitment level does not fix this. It says how settled a block must be on the node that answers, and it says nothing about which slot that node has reached. The tool that does pin the view is `minContextSlot`, an optional field on most read calls. The node compares its own slot with the number you pass. If it is behind, it refuses with error -32016 and answers nothing, so a stale view can never reach your code as if it were fresh.

A reply from `getAccountInfo`, `getBalance`, `getLatestBlockhash` and the other context-wrapped reads carries a `context.slot`, the slot of the view it came from. That number is what you feed forward. Take it from the first read, pass it as the floor on the next one, and a chain of reads stops going backwards. For the commitment ladder itself, see [Solana commitment levels](https://carbium.sh/library/howsolana/solana-commitment-levels).

## 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 address is an optional argument and defaults to the USDC mint. Every call runs at `confirmed`, which is also what the kit fills in when a call leaves commitment out, and the file passes it anyway so the level is visible.

`main.ts` (run: `node main.ts [address]`)

```ts
// HS0029 · Consistent reads with minContextSlot
// https://carbium.sh/library/howsolana/consistent-reads-with-mincontextslot
// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.
// SPDX-License-Identifier: MIT

import { setTimeout as sleep } from "node:timers/promises";
import {
  address,
  createDefaultRpcTransport,
  createSolanaRpcFromTransport,
  isSolanaError,
  SOLANA_ERROR__JSON_RPC__INVALID_PARAMS,
  SOLANA_ERROR__JSON_RPC__METHOD_NOT_FOUND,
  SOLANA_ERROR__JSON_RPC__SERVER_ERROR_MIN_CONTEXT_SLOT_NOT_REACHED,
  SOLANA_ERROR__RPC__TRANSPORT_HTTP_ERROR,
} 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 target = address(process.argv[2] ?? "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v");

// Milliseconds to wait before the next try, or null when a retry cannot help.
function delay(e: unknown, attempt: number): number | null {
  const backoff = 200 * 2 ** (attempt - 1) + Math.random() * 100;
  if (isSolanaError(e, SOLANA_ERROR__RPC__TRANSPORT_HTTP_ERROR)) {
    if (e.context.statusCode === 429) return (Number(e.context.headers.get("retry-after")) || 1) * 1000 + Math.random() * 100;
    return e.context.statusCode >= 500 ? backoff : null;
  }
  if (isSolanaError(e, SOLANA_ERROR__JSON_RPC__SERVER_ERROR_MIN_CONTEXT_SLOT_NOT_REACHED)) return 250;
  if (isSolanaError(e, SOLANA_ERROR__JSON_RPC__METHOD_NOT_FOUND)) return null;
  if (isSolanaError(e, SOLANA_ERROR__JSON_RPC__INVALID_PARAMS)) return null;
  const text = `${(e as Error)?.name} ${(e as Error)?.message}`;
  return /TimeoutError|AbortError|fetch failed|ECONN|ETIMEDOUT/i.test(text) ? backoff : null;
}

async function retrying<T>(label: string, tries: number, call: (s: AbortSignal) => Promise<T>): Promise<T> {
  for (let attempt = 1; ; attempt++) {
    try {
      return await call(AbortSignal.timeout(5000));
    } catch (e) {
      const wait = delay(e, attempt);
      if (wait === null || attempt >= tries) throw e;
      console.error(`${label}: attempt ${attempt} failed, waiting ${Math.round(wait)} ms`);
      await sleep(wait);
    }
  }
}

const tip = await retrying("tip", 3, (abortSignal) =>
  rpc.getLatestBlockhash({ commitment: "confirmed" }).send({ abortSignal }),
);
const floor = tip.context.slot;
console.log(`floor slot ${floor} (from getLatestBlockhash at confirmed)`);

const read = (label: string, tries: number, minContextSlot: bigint) =>
  retrying(label, tries, (abortSignal) =>
    rpc.getAccountInfo(target, { commitment: "confirmed", encoding: "base64", minContextSlot }).send({ abortSignal }),
  );
const [pinned, ahead] = await Promise.allSettled([
  read("pinned", 4, floor),
  read("ahead", 2, floor + 1000n),
]);

if (pinned.status === "fulfilled") {
  const { context, value } = pinned.value;
  console.log(`pinned read answered at slot ${context.slot} (floor ${floor}): ${value ? `${value.lamports} lamports` : "no account"}`);
} else {
  console.error(`pinned read failed: ${pinned.reason}`);
}
console.log(
  ahead.status === "rejected"
    ? `read with a floor 1000 slots ahead refused, as expected: ${String(ahead.reason).split("\n")[0]}`
    : `read with a floor ahead answered at slot ${ahead.value.context.slot}`,
);
```

It reads `getLatestBlockhash` once and keeps only the slot of that view as the floor. It then reads the account with `minContextSlot` set to that floor. Alongside that read, it asks for the same account with a floor 1,000 slots ahead, which no node can satisfy, so the refusal path runs on every execution and you see what a stale-node error looks like in your logs.

Each call goes through one `retrying` function. It gives every attempt its own 5 second timeout with `AbortSignal.timeout`, asks `delay` how long to wait after a failure, and stops when `delay` answers null or the attempts run out. `delay` matches errors by their kit error code with `isSolanaError`, so no check on an HTTP or JSON-RPC error depends on the wording of a message. The two account reads run together with `Promise.allSettled`, so a failure in one still prints the other.

## What each failure gets

Retrying everything the same way is the common mistake. A timeout, a rate limit and a stale node each have a different cause and a different right wait. An error that cannot change on a second try should surface at once, because retrying it only adds load.

| Failure | Retry | Wait |
|---|---|---|
| HTTP 429 | Yes | The seconds in the retry-after header, plus up to 100 ms of jitter |
| -32016, slot not reached | Yes | 250 ms, a little over one slot |
| Timeout or dropped connection | Yes | 200 ms doubled per attempt, plus up to 100 ms of jitter |
| HTTP 5xx | Yes | Same as a timeout |
| -32601, -32602, 401 or any other error | No | Surface it at once |

The wait for a stale node is short on purpose. A slot lasts about 200 ms since the Alpenglow switch, so a node that is one or two slots behind catches up within a retry or two. If it is still refusing after four tries, the node is more than a blip behind, and the next step belongs to the caller: report the read as unavailable or try another endpoint.

Jitter matters when many workers share one key. Without it, every worker that hit the same limit wakes at the same instant and hits it again. A random 0 to 100 ms spread breaks the lockstep at no cost.

## Choosing the floor

The floor should be a slot your app has already seen.

- The `context.slot` of the last reply you accepted. Reads then never go backwards inside one session or one request.
- The slot a write landed in, taken from a `getSignatureStatuses` reply for your own transaction. A read after your write then cannot predate the write.
- A slot from a poll that every worker shares, kept in one place, when several processes must agree on what the chain looked like.

A floor beyond what the cluster has reached cannot be met, however often you retry. That is why the file's second read uses a number far ahead of the tip: the retries run out and the error comes through. In real code a refusal that persists past a few tries means the floor is wrong, or the node is stuck, and the loop should stop instead of waiting on it.

## On Carbium

A call over its rate waits once at the door and is served if its cells refill within 1 s. Past that it gets 429 with a retry-after hint, which is the header `delay` reads. [Limits belong to the account](https://carbium.sh/docs#limits), so every key on it draws from one budget. A worker pool that retries without reading the hint spends that shared budget faster, so the hint is worth honouring.

`getAccountInfo` is one of the [account reads](https://carbium.sh/docs#rpc), priced at 10 cells per call: 0.5 req/s on Free, 15 on Dev, 50 on Business and 400 on Pro. A rate class absorbs bursts of up to 1,024 cells or one second of its rate, whichever is larger.

`-32601` means the method is not served or not found, and [retrying it cannot help](https://carbium.sh/docs#errors). An unknown key gets 401 at the door, and retrying cannot help that either.

To get told when your own limits start biting, see [RPC rate-limit alerts](https://carbium.sh/library/usecase/rpc-rate-limit-alerts).

## Where it ends

`minContextSlot` guards one read against an older view. It does not make a set of reads one snapshot. Two calls with the same floor can still answer from different slots above it, so a total built from several reads can mix moments. When the numbers must agree, fetch them in one call, such as `getMultipleAccounts`, which answers from a single slot.

A floor also says nothing about commitment. It orders your own reads against each other, and it does not make processed, confirmed and finalized agree with one another.

The file retries reads only. Retrying a send needs its own care. One signed transaction lands at most once, but a send that timed out may already have landed, so a rebuilt copy with a fresh blockhash can land a second time. A send path should resubmit the same signed bytes while the blockhash is valid and check the signature, and build a new transaction only once that blockhash has expired and the signature is still absent.

The file makes no decision from what it reads, and it has no circuit breaker. When an endpoint fails for minutes, a loop that retries four times per call still adds load on every caller. A real service adds a limit on in-flight retries across the process and stops sending to a failing endpoint for a while.

A slot your node reached at processed can still end up on a dropped fork. A floor taken from a processed read inherits that risk. Take the floor from a `confirmed` or `finalized` reply when the read after it matters.

## When it goes wrong

| What goes wrong | What to do |
|---|---|
| Every retry of a read returns -32016. | The floor is ahead of what the node has reached, or the node is stuck behind. Check where the floor came from. If it is a slot you saw in a reply, stop after a few tries and report the read as unavailable. |
| HTTP 429 repeats after waiting the retry-after seconds. | The account is over its budget for that method, and every key on it shares that budget. Slow the loop, cap the workers that retry at once, or move to a plan with a higher rate for the method. |
| A call hangs and never errors. | No timeout was set. Pass `abortSignal: AbortSignal.timeout(5000)` to `send`, as the file does, and treat the abort as a retryable failure. |
| Workers wake together and hit the limit again. | Add jitter to the wait. A random 100 ms on top of the backoff spreads them out. |
| Error -32601 on a method that worked on another endpoint. | The method is not served here. Do not retry it. Check the name, or use a method the endpoint serves. |
| The file stops with `Set CARBIUM_KEY to your Carbium API key.` | Export CARBIUM_KEY in the shell that runs `node main.ts`. The file reads it from the environment and never prints it. |

## Questions

### Should I retry a timeout on a send as well as on a read?

Not with the same code. A timed-out send may have landed. Check the signature with `getSignatureStatuses` first, and resend the same signed bytes only if it is absent.

### Does minContextSlot cost more than a plain read?

A `getAccountInfo` costs 10 cells a call, with the field or without it.

### How many retries should a read get?

Three or four, each with its own timeout, covers a node a slot or two behind and a short network blip. Past that the cause has not gone away, and more tries add load.

### Can I use minContextSlot on every method?

Many reads accept it, including `getAccountInfo`, `getBalance`, `getMultipleAccounts` and `getLatestBlockhash`. Check the method's parameters before you rely on it.

## Related

- [Solana commitment levels](https://carbium.sh/library/howsolana/solana-commitment-levels) (How to use Solana, HS0003)
- [RPC rate-limit alerts](https://carbium.sh/library/usecase/rpc-rate-limit-alerts) (Use cases, UC0001)
- [carbium.sh/docs#rpc](https://carbium.sh/docs#rpc)
- [carbium.sh/docs#limits](https://carbium.sh/docs#limits)
- [carbium.sh/docs#errors](https://carbium.sh/docs#errors)
