---
id: I0096
title: "Socket.IO transaction status rooms"
url: https://carbium.sh/library/integrate/socket-io-transaction-status-rooms
collection: Integrations
category: Web frameworks
revision: 1
updated: 2026-11-23
author: Carbium
code: MIT (LICENSE in the zip); text: all rights reserved, Carbium Corporation
---

# Socket.IO transaction status rooms

One room per signature. A hub opens three signatureSubscribe calls on Carbium, one per commitment, and pushes each state to every client in the room. The file runs a two-client demo against the newest signature of a busy address.

## One room per signature

A checkout page, a wallet and an admin panel often have several browsers waiting on the same transaction. If each browser polls, your server pays for every poll. A Socket.IO room removes that fan-out: the server watches the signature once, and every socket that joined the room named after that signature receives each change.

The Solana side is `signatureSubscribe` on the [WebSocket endpoint](https://carbium.sh/docs/endpoints), `wss://services.carbium.sh`, with the key on the URL as `?api-key=`. A [signature subscription](https://carbium.sh/docs/websocket) sends one notification and then ends. To follow a transaction through its stages you open one subscription per commitment level, so the hub opens three for each signature: processed, confirmed and finalized.

The file has no Socket.IO dependency, so the demo runs anywhere Node 24 runs. It carries a small room hub with the same two verbs, join and emit. In a Socket.IO server the join becomes `socket.join(signature)` inside a `watch` handler, and the emit becomes `io.to(signature).emit("status", status)`. The code that talks to Carbium stays as written.

## The states a signature passes through

Five states reach the room. Three follow the commitment levels, `failed` takes the place of whichever level first carries an error, and `unseen` covers a signature the node never saw.

| State | What it means | Closes the watch |
|---|---|---|
| `unseen` | No notification and no status after the wait. The transaction has not reached this node, or it was dropped on the way. | No |
| `processed` | The node executed the transaction in a slot. That slot can still be abandoned. | No |
| `confirmed` | A supermajority of stake voted for the slot. | No |
| `finalized` | The slot is final and cannot be rolled back. | Yes |
| `failed` | The transaction landed with an error. Its fee was still charged. | Yes |

Since the Alpenglow switch a slot lasts about 200 ms and finalized sits 0 to 1 slots behind processed. A room can therefore see all three levels for one signature within a short span, two levels can report the same slot, and the events can arrive briefly out of order. A client should keep the highest state it has seen and never step backwards to a lower one.

A processed event is a report, and the slot behind it can still end up skipped when its fork is dropped. In that case the confirmed and finalized events never arrive for the signature. Show processed as in progress, and treat confirmed or finalized as the point where you act.

A failed transaction reports its error at the first level that carries it, and the hub closes the watch there. The error object is the same one a `getTransaction` call returns in `meta.err`.

## The hub

Save the file as `main.ts` and run it with Node 24, which strips the types on load. It needs `CARBIUM_KEY` and exits with a message when it is unset. `CARBIUM_RPC_URL` and `CARBIUM_WS_URL` are optional and default to the two Carbium endpoints. The first argument is an address with steady traffic, and the Token program is the default. The file asks for that address's newest signature with `getSignaturesForAddress`, then watches it.

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

```ts
// I0096 · Socket.IO transaction status rooms
// https://carbium.sh/library/integrate/socket-io-transaction-status-rooms
// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.
// SPDX-License-Identifier: MIT

import { address, createDefaultRpcTransport, createSolanaRpcFromTransport, signature } from "@solana/kit";
const key = process.env.CARBIUM_KEY;
if (!key) {
  console.error("Set CARBIUM_KEY.");
  process.exit(1);
}
const rpc = createSolanaRpcFromTransport(
  createDefaultRpcTransport({ url: process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh", headers: { "x-api-key": key } }),
);
const wsUrl = `${process.env.CARBIUM_WS_URL ?? "wss://services.carbium.sh"}?api-key=${key}`;
const levels = ["processed", "confirmed", "finalized"];

// The room hub: join replays what the room already saw, emit pushes a status to every member.
type Status = { state: string; slot?: number; err?: unknown };
const members = new Map<string, Set<(s: Status) => void>>();
const history = new Map<string, Status[]>();
function join(room: string, send: (s: Status) => void) {
  if (!members.has(room)) members.set(room, new Set());
  members.get(room)!.add(send);
  for (const s of history.get(room) ?? []) send(s);
}
function emit(room: string, s: Status) {
  history.set(room, [...(history.get(room) ?? []), s]);
  for (const send of members.get(room) ?? []) send(s);
}

// One signatureSubscribe per commitment; each notification becomes a room event.
function track(sig: string, done: () => void) {
  const ws = new WebSocket(wsUrl);
  const level = new Map<number, string>(); // subscription id -> commitment
  ws.onopen = () => levels.forEach((commitment, i) =>
    ws.send(JSON.stringify({ jsonrpc: "2.0", id: i, method: "signatureSubscribe", params: [sig, { commitment }] })));
  ws.onmessage = (e) => {
    const m = JSON.parse(String(e.data));
    if (typeof m.result === "number") level.set(m.result, levels[m.id]);
    if (m.method !== "signatureNotification") return;
    const { context, value } = m.params.result;
    const state = level.get(m.params.subscription) ?? "unknown";
    emit(sig, value.err ? { state: "failed", slot: context.slot, err: value.err } : { state, slot: context.slot });
    if (value.err || state === "finalized") { ws.close(); done(); }
  };
  ws.onerror = () => console.error("websocket error"); // the URL carries the key, never print it
  setTimeout(async () => {
    if (history.has(sig)) return;
    try {
      const [status] = (await rpc.getSignatureStatuses([signature(sig)]).send()).value;
      if (!status) emit(sig, { state: "unseen" });
    } catch (e) { console.error("status check failed:", String(e)); }
  }, 8000);
}

async function main() {
  const watched = process.argv[2] ?? "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
  const [newest] = await rpc.getSignaturesForAddress(address(watched), { limit: 1 }).send();
  if (!newest) { console.error("no signatures for that address"); process.exit(1); }
  const t0 = Date.now();
  console.log(`room ${newest.signature.slice(0, 12)}`);
  for (const name of ["client-a", "client-b"]) {
    join(newest.signature, (s) => console.log(`${name} +${Date.now() - t0}ms ${s.state}${s.slot ? ` slot ${s.slot}` : ""}`));
  }
  track(newest.signature, () => setTimeout(() => process.exit(0), 200));
  setTimeout(() => { console.error("no final state in 25 s"); process.exit(1); }, 25_000);
}
main().catch((e) => { console.error(String(e)); process.exit(1); });
```

## Run it and wire in your own signature

Start it with `node main.ts`. It prints the first twelve characters of the room name, then one line per client for each event, each with the milliseconds since the watch began and the slot. Two clients join the same room, so every event prints twice. The newest signature has usually reached confirmed and often finalized, and a subscription opened on a signature that has reached a level answers at once, so all three levels can print within the same few milliseconds at one slot. The process exits after the finalized line. If no final state arrives in 25 seconds it prints a message and exits with status 1.

For your own transaction, call `track(signature, ...)` with the signature your app got back from `sendTransaction`, and let each browser join the room by that string. Starting the watch before or just after the send works, because a late subscription still receives the levels already reached. A client that joins late gets the room's history replayed from memory, so a page that reloads mid-way catches up.

The `unseen` state comes from a timer. Eight seconds after the watch starts, if the room has seen nothing, the hub asks `getSignatureStatuses` once. A null answer means the node knows nothing about the signature and the room hears `unseen`. The client can then show a waiting state, and the server can decide whether to resend the same signed transaction until its blockhash expires. See [Transaction status check](https://carbium.sh/library/howsolana/transaction-status-check) for the one-shot version of that read.

A call without commitment through @solana/kit uses confirmed, and the JSON-RPC server's own default is finalized. The demo's `getSignaturesForAddress` call therefore reads at confirmed, which is why its newest signature has usually reached that level already.

## What a watched signature costs

Each signature opens three subscriptions. A signature subscription is the lightest weight, 5 credits to open, so a watch costs 15 credits to open, then 20 credits per MiB sent. Each notification is small, and the [credit schedule](https://carbium.sh/docs/limits) charges nothing for a refused subscription. Read the meter after a short run before you multiply by your daily order count.

The hub opens one socket for each tracked signature. Your plan [caps connections and subscriptions](https://carbium.sh/docs/websocket) per account, and Free carries 5 sockets. Limits are per account, so all of its keys share that budget, and five transactions in flight use all five sockets on Free. A shop with many open orders needs a plan whose cap matches them, or the shared socket described below.

The one `getSignaturesForAddress` call in the demo costs 50 cells and takes the key in the `x-api-key` header. Your real flow does not make it, because your own app already holds the signature.

## Where it ends

- One socket per signature. A production hub shares one socket across its signatures within the plan's subscription cap, maps each subscription id to its room and level, and routes each notification to its room.
- No reconnect. When Carbium closes a socket the room goes quiet. Open a new socket and subscribe again, and the levels already reached answer at once.
- History stays in memory for the life of the process and is never trimmed. Delete a room's history and members after its closing state when the process runs for days.
- Anyone who knows a signature can join its room, and signatures are public on chain. Put no private order data in the payload the room pushes.
- `unseen` is a guess made at one moment. A signature can still land after the check, so stop resending only when the blockhash has expired.
- The run proves the Solana half against Carbium. It does not start Socket.IO, so the `socket.join` and `io.to(...).emit` lines belong to your server and are not exercised here.

## When it goes wrong

| What goes wrong | What to do |
|---|---|
| The run exits at once with a 401 error, or prints a websocket error and exits after 25 seconds with no final state. | A 401 from the first call means Carbium does not know the key: an unknown key gets 401 at the door, so check that `CARBIUM_KEY` holds the whole key. A websocket error after a good first call points at the socket: check that `CARBIUM_WS_URL`, if set, is the wss address of the endpoint, and that the account has a socket free under its plan's cap. |
| The run prints no signatures for the address. | The address has nothing in the address index, which keeps up to 30 days. Pass an address with recent traffic as the first argument. |
| A room shows unseen for a transaction you just sent. | The node has not seen it yet or it was dropped. Wait, check again, and resend the same signed transaction only until its blockhash expires. |
| The sixth tracked signature on a Free account never gets a working socket. | The account is at its socket cap. Share one socket across signatures, or move to a plan with a higher cap. |
| A client shows confirmed after it showed finalized, or the same slot twice. | The levels can arrive close together and out of order. Keep the highest state seen per signature and ignore anything lower. |
| A failed state arrives with an error object you cannot read. | Fetch the transaction with `getTransaction` and `maxSupportedTransactionVersion: 1` and read its logs. Without that setting, a v1 transaction answers -32015. |

## Questions

### Do I need socket.io installed to use this?

No. The file has its own join and emit so the demo has no dependency. In your server, replace the two functions with `socket.join` and `io.to(room).emit`, send the room's history to a socket when it joins, and keep the rest.

### Why three subscriptions and not one at finalized?

A page that waits for finalized shows nothing until the end. Three levels let it show progress, and a checkout can act at confirmed while a ledger waits for finalized.

### What happens if I subscribe after the transaction already finalized?

Each subscription answers at once with its level, and the demo relies on that. Your room receives processed, confirmed and finalized in quick succession.

### Can one room carry several signatures?

The file keys a room by one signature, so each room has one lifecycle. For an order with several transactions, join the client to one room per signature.

## Related

- [Transaction status check](https://carbium.sh/library/howsolana/transaction-status-check) (How to use Solana, HS0008)
- [Pusher wallet activity channels](https://carbium.sh/library/integrate/pusher-wallet-activity-channels) (Integrations, I0092)
- [carbium.sh/docs/websocket](https://carbium.sh/docs/websocket)
- [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/rpc](https://carbium.sh/docs/rpc)
