---
id: HS0041
title: "Webhook-to-RPC fetch retries"
url: https://carbium.sh/library/howsolana/webhook-to-rpc-fetch-retries
collection: How to use Solana
category: Webhooks
revision: 1
updated: 2026-11-22
author: Carbium
code: MIT (LICENSE in the zip); text: all rights reserved, Carbium Corporation
---

# Webhook-to-RPC fetch retries

A small Node.js file that takes a signature from a webhook, or an address to pull a fresh one from, and fetches the transaction with backoff until the node has it. It prints each attempt and only reads.

## Why the first fetch finds nothing

A webhook sender watches the chain from its own node and posts the signature as soon as it sees the transaction. Your server then asks a different node for that transaction. If the node has not processed the slot yet, `getTransaction` answers `null`. That is a valid result: the signature is real and the answer came early.

The race is short and uneven. Your handler runs within milliseconds of the post, events can arrive in bursts, and the node you query may sit a slot or two behind the sender's. A single fetch inside the handler loses that race some of the time. In your logs it looks like a missing transaction, while the transaction is already on chain.

Commitment is the second cause. A webhook can fire at `processed`, and a call at a higher level answers `null` until the transaction reaches it. `getTransaction` accepts only `confirmed` or `finalized`, so lowering the fetch level cannot match a processed webhook and the wait is always needed. A raw JSON-RPC fetch that leaves commitment out waits for finalized, which on mainnet now trails processed by about a slot. The handler here names `confirmed` in the call, so the level it waits for is visible in the code.

## The code

Install `@solana/kit` at 8.6.0, export `CARBIUM_KEY` and run the file with Node 24, which strips TypeScript types on load. Pass the signature from your webhook payload. Pass an address instead and the file takes that address's newest signature, so you can try it before a live event reaches you.

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

```ts
// HS0041 · Webhook-to-RPC fetch retries
// https://carbium.sh/library/howsolana/webhook-to-rpc-fetch-retries
// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.
// SPDX-License-Identifier: MIT

import { setTimeout as sleep } from "node:timers/promises";
import {
  createDefaultRpcTransport,
  createSolanaRpcFromTransport,
  isAddress,
  isSolanaError,
  signature,
  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 arg = process.argv[2];
if (!arg) {
  console.error("Usage: node main.ts <signature-or-address>");
  process.exit(1);
}

const MAX_ATTEMPTS = 8;
let throttled = 0;

// Fetch one transaction: sleep 200 ms and double up to 2 s on null, wait out a 429.
async function fetchTransaction(sig: ReturnType<typeof signature>) {
  for (let attempt = 1; attempt <= MAX_ATTEMPTS; attempt++) {
    try {
      const tx = await rpc
        .getTransaction(sig, {
          commitment: "confirmed",
          encoding: "json",
          maxSupportedTransactionVersion: 1,
        })
        .send();
      if (tx !== null) return { tx, attempt };
      console.log(`attempt ${attempt}: null`);
      if (attempt < MAX_ATTEMPTS) await sleep(Math.min(200 * 2 ** (attempt - 1), 2000));
    } catch (e) {
      if (!isSolanaError(e, SOLANA_ERROR__RPC__TRANSPORT_HTTP_ERROR) || e.context.statusCode !== 429) throw e;
      throttled++;
      const seconds = Number(e.context.headers.get("retry-after")) || 1;
      console.log(`attempt ${attempt}: 429, waiting ${seconds}s`);
      await sleep(seconds * 1000);
    }
  }
  return null;
}

// An address gives its newest signature; anything else must be a signature.
let sig;
if (isAddress(arg)) {
  const rows = await rpc.getSignaturesForAddress(arg, { limit: 1, commitment: "confirmed" }).send();
  if (rows.length === 0) {
    console.log("No signatures for that address.");
    process.exit(0);
  }
  sig = rows[0].signature;
} else {
  sig = signature(arg);
}
console.log(`fetching ${sig}`);

const found = await fetchTransaction(sig);
if (found === null) {
  console.log(`gave up after ${MAX_ATTEMPTS} attempts (${throttled} were 429, ${MAX_ATTEMPTS - throttled} were null): log it and move on`);
} else {
  const { tx, attempt } = found;
  // Failed transactions carry bigint values in err, which JSON.stringify refuses without a replacer.
  const err = JSON.stringify(tx.meta?.err, (_k, v) => (typeof v === "bigint" ? v.toString() : v));
  console.log(`found on attempt ${attempt}: slot=${tx.slot} err=${err} fee=${tx.meta?.fee}`);
}
```

Each attempt asks at `confirmed` with `encoding: "json"` and `maxSupportedTransactionVersion: 1`, so a v1 transaction comes back and is not refused with -32015. A `null` sleeps 200 ms, doubles the sleep each time and stops growing at 2 s, for at most eight attempts. Any error other than a 429 throws at once, because a malformed signature or a method the endpoint does not serve does not get better with waiting.

## The retry schedule

| Attempt | Sleep after a null |
|---|---|
| 1 | 200 ms |
| 2 | 400 ms |
| 3 | 800 ms |
| 4 | 1.6 s |
| 5 to 7 | 2 s each |
| 8 | none, the file gives up |

The seven sleeps add up to 9 seconds. Pick your own numbers from what the worker can afford: a lag of a slot or two is settled by the first few attempts.

Keep the loop out of the webhook request. Answer the sender with a 200 at once, put the signature on a queue and run the fetch from a worker. Senders time out and resend, and a handler that waits turns one event into several. Key the work by signature so a resent event finds the row already done.

## On Carbium

Calls go to `https://services.carbium.sh`. A retry loop multiplies calls, so the cost is worth reading before you set the attempt count. `getTransaction` [costs 50 cells](https://carbium.sh/docs#rpc) and runs at 0.24, 1.2, 5 and 25 req/s on Free, Dev, Business and Pro, so eight attempts on one signature are up to 400 cells.

A rate class absorbs a burst of 1,024 cells on Free, Dev and Business, which is about twenty `getTransaction` calls at 50 cells, and one second of the rate on Pro, where 25 req/s at 50 cells is 1,250 cells. The class then refills at its rate. A burst of webhooks that all retry at once can spend that quickly. [Limits are per account](https://carbium.sh/docs#limits), so every key on the account draws on the same budget.

A call past its rate gets HTTP 429 with a retry-after header, and the file sleeps that many seconds before its next attempt. The 429 counts as one of the eight attempts, so a steady 429 ends the run. The cure is a worker pool with a fixed size that sets the call rate.

The address mode adds one `getSignaturesForAddress` call. It costs 50 cells and runs at 0.24 req/s on Free, 1.2 on Dev, 100 on Business and 500 on Pro.

## Where it ends

A webhook that fires at `processed` can announce a transaction whose fork is later dropped, and no retry finds that one. After the last attempt, log the signature and move on. A loop with no ceiling only hides the miss and holds a worker.

A signature from another cluster, or one cut short when it was copied, answers `null` at every attempt too. The file checks that the text is a valid base58 signature before any request leaves, and it cannot tell which cluster produced it.

Old signatures need care. `getSignaturesForAddress` on Carbium reads from an address index that keeps up to 30 days, and its pages reach below the validator's ledger floor, so `getTransaction` can answer `null` for an older signature the list returned. That is a ledger limit and more attempts do not change it. The address mode here takes the newest signature, which is always inside the ledger.

The file does not check that the webhook came from your sender. Verify its auth header or shared secret in your handler. The fetched transaction is the better source for amounts and accounts, so compare it to the payload and trust the chain.

The schedule has no jitter. If many workers start on the same event they retry in lockstep, and a random few percent added to each sleep spreads them. For the larger picture of receiving events, see [Address transaction webhooks](https://carbium.sh/library/howsolana/address-transaction-webhooks).

## When it goes wrong

| What goes wrong | What to do |
|---|---|
| Every attempt answers `null` for a signature the webhook sent. | Check that the whole signature was copied and that the sender and your RPC read the same cluster. If both are right, the sender may fire at `processed` and the transaction sat on a dropped fork. Log it and stop after the last attempt. |
| Error -32015 on a transaction that exists. | The call left out `maxSupportedTransactionVersion`, or set it to 0, and the transaction is v1. Pass `maxSupportedTransactionVersion: 1` with an encoding, as the file does. |
| HTTP 429 on most attempts during a burst of webhooks. | Too many fetches run at once for the plan's req/s. Queue the signatures, run a fixed number of workers and honor the retry-after header. A higher plan raises the rate for the method. |
| The same event is processed twice. | The sender resent after a slow reply. Answer 200 before the fetch and store the signature as a unique key so the second event is skipped. |
| The file throws on its argument before any request leaves. | A signature is 64 bytes, up to 88 base58 characters, most often 87 or 88. Pass the whole signature from the payload, or a 32 to 44 character address for address mode. |

## Questions

### How many attempts are enough?

Eight over about nine seconds covers a node that is a few slots behind the sender. A signature still missing after that is a dropped fork or a wrong cluster far more often than a slow node.

### Should I fetch at finalized to be safe?

You can pass `commitment: "finalized"`. The extra wait is a slot or so, and it suits work that must not be undone. `confirmed` is what the file uses.

### Can I just check the status instead of fetching?

[Transaction status check](https://carbium.sh/library/howsolana/transaction-status-check) shows how to poll `getSignatureStatuses`, which tells you whether a signature landed. It does not return the accounts, logs or fee, so you still fetch the transaction once it lands.

### Why not retry inside the webhook handler?

The sender waits on your reply and resends when it is slow. Reply first, then fetch from a queue, and the retries cost nothing in the sender's eyes.

## Related

- [Address transaction webhooks](https://carbium.sh/library/howsolana/address-transaction-webhooks) (How to use Solana, HS0018)
- [On-chain event webhooks](https://carbium.sh/library/blockchainideas/on-chain-event-webhooks) (Blockchain ideas, BI0013)
- [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)
