---
id: HS0163
title: "Incremental signature sync"
url: https://carbium.sh/library/howsolana/incremental-signature-sync
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
---

# Incremental signature sync

One TypeScript file stores the newest signature it has seen for an address, then pages getSignaturesForAddress back to that checkpoint with until on each run. It reads only: no key pair, no transaction fetch, and one JSON state file in the working directory.

## How the two cursors bound a read

`getSignaturesForAddress` lists the transactions that touched one address, newest first. Two cursors bound the walk. `before` starts the walk after a signature and moves backward. `until` stops the walk at a signature. Neither cursor appears in the result, so a call with `until` set to your checkpoint returns the rows that landed after it and never repeats the checkpoint row.

One call returns at most 1,000 rows, and 1,000 is also the default. The code asks for 200 a call. Each page passes `before` set to the oldest row of the page before it, so pages join with no overlap and no gap between them. A page shorter than the limit means the walk reached `until`, or the oldest row the index holds. The paging rules are the same ones [signature history](https://carbium.sh/library/howsolana/signature-history-pagination) walks through for a single address.

The walk starts at the top, so a run that finds more new rows than its page budget sees only the newest ones. The rows between the checkpoint and that window stay unread. The code treats that case as a gap, and it keeps the old checkpoint so a later run with a larger budget can close it.

## Why an older range returns the same rows

A range from `until` to `before` stays put between two reads for two reasons. New activity lands newer than the head of the previous read, so it appears above the range and never inside it. And the rows in the range are settled when the read asks for `finalized`. Since the Alpenglow switch, finalized sits 0 to 1 slots behind processed, and a finalized row is one the chain will not roll back.

The checkpoint is the part that can go wrong. A row read at `processed` can be dropped with its fork, and a checkpoint on that row would anchor the next run on a signature that no longer exists in the chain's history. The JSON-RPC server defaults to `finalized`, but `@solana/kit` 8.6.0 sends `confirmed` when a call leaves commitment out, so this code sets `finalized` on every call.

## The code

Install `@solana/kit` at 8.6.0, export `CARBIUM_KEY` and run the file with Node 24, which strips the types itself. The address is the one argument. The run reads at most five pages of 200 rows and keeps the newest signature in `sync-state.json` in the working directory. The file stores the address with the checkpoint, so a state file from another address is ignored.

`main.ts` (run: `node main.ts <address>`)

```ts
// HS0163 · Incremental signature sync
// https://carbium.sh/library/howsolana/incremental-signature-sync
// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.
// SPDX-License-Identifier: MIT

import { readFile, writeFile } from "node:fs/promises";
import {
  address,
  createDefaultRpcTransport,
  createSolanaRpcFromTransport,
  signature,
  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 } }),
);

const [addrArg] = process.argv.slice(2);
if (!addrArg) {
  console.error("Usage: node main.ts <address>");
  process.exit(1);
}
const addr = address(addrArg);

const STATE = "sync-state.json"; // written to the working directory
const PAGE = 200; // rows per call, below the 1,000 maximum
const MAX_PAGES = 5; // at most 1,000 new rows per run

type Checkpoint = { address: string; newest: string };
type Row = { signature: Signature; slot: bigint; err: unknown };

async function loadCheckpoint(): Promise<Checkpoint | null> {
  try {
    const saved = JSON.parse(await readFile(STATE, "utf8")) as Checkpoint;
    return saved.address === addrArg ? saved : null;
  } catch {
    return null;
  }
}

const prior = await loadCheckpoint();
const until = prior ? signature(prior.newest) : undefined;
const rows: Row[] = [];
let before: Signature | undefined;
let complete = false;

// Newest first. Each page starts before the oldest row of the last page.
for (let page = 0; page < MAX_PAGES && !complete; page++) {
  const batch = await rpc
    .getSignaturesForAddress(addr, { before, until, limit: PAGE, commitment: "finalized" })
    .send();
  rows.push(...batch);
  complete = batch.length < PAGE;
  before = batch[batch.length - 1]?.signature;
}

const newest = rows[0]?.signature;
const failed = rows.filter((r) => r.err !== null).length;
console.log(prior ? `resumed after checkpoint ${prior.newest}` : "no checkpoint yet: reading from the newest row");
console.log(`${rows.length} new rows, ${failed} with an error`);

if (newest && (!prior || complete)) {
  const saved: Checkpoint = { address: addrArg, newest };
  await writeFile(STATE, JSON.stringify(saved));
  console.log(`checkpoint saved: ${newest}`);
} else if (prior && !complete) {
  console.log(`gap: more than ${PAGE * MAX_PAGES} new rows; checkpoint kept, run again with a larger MAX_PAGES`);
}
```

The RPC client is created once, and every call goes to the endpoint from `CARBIUM_RPC_URL`, with the key in the `x-api-key` header. The loop feeds each page's last signature back in as `before`, and the stored checkpoint goes in as `until`. The checkpoint file is written only once the walk is complete, or on the first run, which starts the sync from the newest row. A thrown error stops the run before that write, so the next run starts from the same checkpoint.

## Reading the answer

| Field | Type | Meaning |
|---|---|---|
| signature | string | The transaction id. It is the cursor for `before` and `until`. |
| slot | bigint | The slot the transaction landed in. Rows sort by slot, then by position in the slot. |
| err | object or null | Null when the transaction succeeded. A failed transaction still appears in the list. |

Rows come back newest first, so `rows[0]` is the head of the run and the value the code saves. The list says that a transaction touched the address. It does not return the transaction itself: a separate `getTransaction` call reads it, and that call can answer null for an old signature the list still shows, because the index reaches below the ledger floor.

## On Carbium

`getSignaturesForAddress` costs 50 cells a call. The rate is 0.24 calls per second on Free, 1.2 on Dev, 100 on Business and 500 on Pro. A backfill of five pages is five calls and 250 cells, which stays inside the 1,024-cell burst. After that, a run costs one call for each 200 new rows it reads.

The address index behind the call keeps up to 30 days. An empty page past 30 days shows the index's age limit, and the address may have older transactions than the index can list. The [index note](https://carbium.sh/docs/migrate) explains the ledger floor behind this.

## Where it ends

The sync reaches only as far back as the 30-day index. A checkpoint older than that gets a short page at the age limit, and the code reads the short page as a finished walk. The days between the checkpoint and the index floor are then never read. A reader who must keep every row needs a separate source for those days.

The code does not retry a failed page and does not sort by block time. A row is a listing, not a result: an `err` of null shows the transaction succeeded, not that the instruction did what your app expects, so read the transaction for that. The state file holds one address. Many addresses need one checkpoint each.

A busy address can outgrow the budget between two runs. The gap message names the case, and the checkpoint stays where it was. Without the state file, the next run starts again from the newest rows, so rows that landed while the file was missing are read only if they fit in the first 1,000.

## When it goes wrong

| What goes wrong | What to do |
|---|---|
| The run prints a gap message on every run. | The address gained more than 1,000 rows since the checkpoint. Raise `MAX_PAGES` for one run, check that the gap message clears, then keep the budget at a size that fits the address's pace. |
| HTTP 429 with a retry-after hint. | Wait for the number of seconds in the header and run again. The checkpoint was not written, so nothing is lost, and the run reads the same rows again. |
| The run starts from the newest rows again after a restart. | The state file is read from the working directory. Start the run from the same folder every time, or the code finds no checkpoint and starts over. |
| A signature from the list answers null from `getTransaction`. | Handle null in the caller. The list reaches below the ledger floor, so a null for an old signature is the index age at work, not a broken call. |
| Error -32602 Invalid param on the address argument. | The argument is not a base58 public key. `address()` rejects it before any call leaves, so check the spelling and copy the address again. |
| A row from a saved checkpoint is missing on a later run. | The checkpoint may have been saved at processed commitment before a fork was dropped. Delete `sync-state.json`, run again to resync from the newest rows, and keep the `finalized` setting on every call. |

## Questions

### Will the same until and before range return the same rows on two reads?

Yes for the rows read at `finalized`, because new activity lands above the newest row you read. The range below your checkpoint stays put while it is inside the 30-day index, and rows older than that are not served.

### Why does the run keep the old checkpoint when it stops early?

A gap means the rows between the checkpoint and the oldest page you read were never read. Moving the checkpoint to the newest row would skip them for good.

### Can I sync with `before` alone?

You can page backward with `before` alone, but then you must know where to stop. `until` is the stop signal that keeps each run to the new rows.

### Does a signature in the list mean the transaction succeeded?

No. A row with `err` set is still in the list, so check that field before you count the row as a payment or an event.

### Which commitment should the checkpoint use?

Use `finalized`. A row read at `processed` can be dropped with its fork, and a checkpoint on that row would anchor the next run on a signature that no longer exists.

## Related

- [Signature history pagination](https://carbium.sh/library/howsolana/signature-history-pagination) (How to use Solana, HS0034)
- [Postgres indexer slot checkpoints](https://carbium.sh/library/integrate/postgres-indexer-slot-checkpoints) (Integrations, I0047)
- [carbium.sh/docs/rpc](https://carbium.sh/docs/rpc)
- [carbium.sh/docs/limits](https://carbium.sh/docs/limits)
- [carbium.sh/docs/endpoints](https://carbium.sh/docs/endpoints)
- [carbium.sh/docs/auth](https://carbium.sh/docs/auth)
- [carbium.sh/docs/migrate](https://carbium.sh/docs/migrate)
