---
id: I0134
title: "Step Functions confirmation wait"
url: https://carbium.sh/library/integrate/step-functions-confirmation-wait
collection: Integrations
category: Serverless and edge
revision: 1
updated: 2026-11-23
author: Carbium
code: MIT (LICENSE in the zip); text: all rights reserved, Carbium Corporation
---

# Step Functions confirmation wait

A Lambda task reads one signature's status and the block height on Carbium, returns confirmed, failed, pending or expired, and lets a Choice state decide whether to wait or rebuild.

## What one poll decides

The job is one read-only poll. It takes a signature and the cutoff the sender stored with it, the `lastValidBlockHeight` that came with the blockhash, and returns one verdict. The state machine decides what happens next, so the function never waits inside its own run.

Two reads make the decision: the block height, then the status of the signature at `confirmed`. The verdict depends on that order, and the reason is in its own section below.

| Verdict | When | What the state machine does |
|---|---|---|
| confirmed | Status present, no error, confirmed or finalized | Record it and finish. |
| failed | Status present with an error | Record the error. Do not rebuild, because the transaction landed. |
| pending | No status yet, or only processed, and the height is at or under the cutoff | Wait, then poll again. |
| expired | No status and the height is past the cutoff | The signature cannot land. The sender builds a new transaction with a new blockhash. |
| rate-limited | Carbium answered 429 | Wait for the retry-after value, then poll again. |
| error | Any other failure | Retry a set number of times, then send an alarm. |

## The state machine around it

The sender writes the signature and the cutoff into the workflow state when it submits. The check task receives both as its input. A Choice state reads the verdict and either ends the flow or moves through a Wait state back to the check. A Lambda that sleeps through the wait is billed for every second of the sleep, while a Wait state runs no code.

This file is the command-line form of that task. It reads the two values from `argv`, so a person can run the same check by hand. In a Lambda handler the event fields take the place of `argv`, and the key comes from the function's secret.

## Read the height first

A transaction whose blockhash is still valid can land at any slot up to its cutoff. A status read that finds nothing means little until the height is past the cutoff, so the code reads `getBlockHeight` first and `getSignatureStatuses` second. Reversed, a transaction could land between the two reads and be called expired.

The status read uses `confirmed`, and the code sets it. @solana/kit 8.6.0 fills in `confirmed` when a call leaves commitment out, but setting it here keeps the level visible in the code. Since the Alpenglow switch, finalized sits 0 to 1 slots behind processed, so waiting for finalized would add little to this decision.

A signature that shows only at `processed` stays `pending`. A slot notified at processed can still end up skipped when its fork is dropped, so `confirmed` is the first level the check trusts.

## Endpoint, key and discovery

Calls go to `CARBIUM_RPC_URL`, which defaults to [the RPC endpoint](https://carbium.sh/docs/endpoints). The key comes from `CARBIUM_KEY`, and the code exits with a message when it is missing. Keep that key in the function's secret store, not in the workflow definition, because an execution's history records its input.

With neither value given, the code finds a stand-in: the newest signature of `WATCH_PROGRAM`, read through `getSignaturesForAddress`. That method reads the [address index](https://carbium.sh/docs/migrate), which keeps 30 days. The stand-in cutoff is the current height plus 150 blocks, the window a fresh blockhash gives a sender. The output sets `standIn` to true, so nobody reads it as a sender's real cutoff.

## Run it

Export `CARBIUM_KEY`, then run `node main.ts`. With no arguments it checks the newest signature of a busy Jupiter program and prints one JSON object. Pass a signature and its cutoff, in that order, to check a transaction a sender submitted.

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

```ts
// I0134 · Step Functions confirmation wait
// https://carbium.sh/library/integrate/step-functions-confirmation-wait
// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.
// SPDX-License-Identifier: MIT

import {
  address,
  createDefaultRpcTransport,
  createSolanaRpcFromTransport,
  isSolanaError,
  signature,
  SOLANA_ERROR__RPC__TRANSPORT_HTTP_ERROR,
} from "@solana/kit";

const apiKey = process.env.CARBIUM_KEY;
if (!apiKey) {
  process.stderr.write("CARBIUM_KEY is not set; add your Carbium key and run again.\n");
  process.exit(1);
}

const transport = createDefaultRpcTransport({
  url: process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh",
  headers: { "x-api-key": apiKey },
});
const rpc = createSolanaRpcFromTransport(transport);
const level = "confirmed";
const timeout = () => AbortSignal.timeout(5_000);
const watched = process.env.WATCH_PROGRAM ?? "JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4";
const WINDOW = 150n;

type Probe = { sig: string; cutoff: bigint; standIn: boolean };

// argv: <signature> <lastValidBlockHeight>. Without them, the newest signature of WATCH_PROGRAM
// is used with a stand-in cutoff of the current height plus WINDOW.
async function resolveProbe(): Promise<Probe> {
  const [, , givenSig, givenCutoff] = process.argv;
  if (givenSig && givenCutoff) return { sig: givenSig, cutoff: BigInt(givenCutoff), standIn: false };
  const [latest] = await rpc.getSignaturesForAddress(address(watched), { limit: 1, commitment: level }).send({ abortSignal: timeout() });
  if (!latest) throw new Error(`no recent signature for ${watched}`);
  const tip = await rpc.getBlockHeight({ commitment: level }).send({ abortSignal: timeout() });
  return { sig: latest.signature, cutoff: tip + WINDOW, standIn: true };
}

// Height first: an unseen signature only means expired once the height is past the cutoff.
async function classify(sig: string, cutoff: bigint) {
  const tip = await rpc.getBlockHeight({ commitment: level }).send({ abortSignal: timeout() });
  const { value } = await rpc.getSignatureStatuses([signature(sig)], { searchTransactionHistory: false }).send({ abortSignal: timeout() });
  const hit = value[0];
  const frame = { signature: sig, lastValidBlockHeight: cutoff, blockHeight: tip };
  if (!hit) return { ...frame, verdict: tip > cutoff ? "expired" : "pending" };
  if (hit.err !== null) return { ...frame, verdict: "failed", slot: hit.slot, err: hit.err };
  const landed = hit.confirmationStatus === "confirmed" || hit.confirmationStatus === "finalized";
  return { ...frame, verdict: landed ? "confirmed" : "pending", slot: hit.slot };
}

// Bigints print as strings, so the JSON holds no bigint.
const plainJson = (_key: string, v: unknown) => (typeof v === "bigint" ? v.toString() : v);

try {
  const probe = await resolveProbe();
  const report = { ...(await classify(probe.sig, probe.cutoff)), standIn: probe.standIn, checkedAt: new Date().toISOString() };
  console.log(JSON.stringify(report, plainJson, 2));
} catch (failure) {
  if (isSolanaError(failure, SOLANA_ERROR__RPC__TRANSPORT_HTTP_ERROR) && failure.context.statusCode === 429) {
    console.log(JSON.stringify({ verdict: "rate-limited", retryAfter: failure.context.headers.get("retry-after") }));
  } else {
    console.log(JSON.stringify({ verdict: "error", message: failure instanceof Error ? failure.message : String(failure) }));
  }
}
```

The output carries the verdict, the signature, the slot when one exists, both heights, `standIn` and the check time. A `rate-limited` answer carries the `retryAfter` header, and an `error` carries the message. Nothing in the output holds the key.

## Where it ends

- It reads one signature's status and the block height. It does not read the transaction body, so a failed verdict carries the error object and nothing about the instructions.
- It never sends. An `expired` verdict means the sender must build a new transaction with a new blockhash, and building and signing stay with the sender.
- Discovery covers only the 30-day address index. An older signature has to be passed in with its stored cutoff.
- Each verdict is one read from one node at one moment. A workflow that wants a second read adds one after a Wait state.
- The check trusts the cutoff it is given. A cutoff that is too low makes a live transaction look expired early.
- `pending` does not say whether the transaction reached a leader at all. It says only that no confirmed status exists yet within the window.

## When it goes wrong

| What goes wrong | What to do |
|---|---|
| The verdict is `error` with a 401 in the message, on every poll. | The secret holds a shortened key or the wrong one. Put the whole key in the secret. A key the gateway does not know gets a 401 at the door, see [errors](https://carbium.sh/docs/errors). |
| `expired` comes back for a signature that later shows on chain. | The cutoff was too low, or a stand-in was used. Pass the cutoff the sender stored with that blockhash, and check that `standIn` is false before acting on the verdict. |
| `rate-limited` on every poll. | The account's budget is spent. Route `rate-limited` through the Wait state using the `retryAfter` value, and check the account's [limits](https://carbium.sh/docs/limits) for its plan. |
| `failed` for a transaction the sender believed was dropped. | It landed with an error, so it is on chain. Read the `err` object before rebuilding, and do not submit a new transaction for the same work until that error is understood. |
| `pending` stays on screen past the cutoff in a stored run. | The next read should turn it to `expired`. If it does not, the signature is not the one the sender submitted, or the stored cutoff is wrong. Check the stored pair. |
| The state machine loops on `pending` without end. | Add a maximum poll count to the Choice path, and send the last `pending` to an alarm with the signature. |

## Questions

### Why not wait for confirmation inside the same function?

A function that sleeps is billed while it sleeps, and a wait longer than its timeout is lost. The Wait state keeps each poll short, and each verdict stays in the workflow's history.

### Does this job send or retry the transaction?

No. It reads a signature and a height and returns a verdict. The sender decides whether to build a new transaction after `expired`.

### Why check the height before the status?

An empty status only means expired once the height is already past the cutoff. Reversing the reads can call a transaction expired that landed between them.

### Can it find a signature from last month?

Discovery reads the address index, which keeps 30 days. Pass an older signature directly with its stored cutoff, because discovery does not reach that far back.

## Related

- [Dropped transaction detector](https://carbium.sh/library/howsolana/dropped-transaction-detector) (How to use Solana, HS0028)
- [Transaction status check](https://carbium.sh/library/howsolana/transaction-status-check) (How to use Solana, HS0008)
- [carbium.sh/docs/endpoints](https://carbium.sh/docs/endpoints)
- [carbium.sh/docs/auth](https://carbium.sh/docs/auth)
- [carbium.sh/docs/errors](https://carbium.sh/docs/errors)
- [carbium.sh/docs/limits](https://carbium.sh/docs/limits)
- [carbium.sh/docs/migrate](https://carbium.sh/docs/migrate)
- [carbium.sh/docs/rpc](https://carbium.sh/docs/rpc)
