Solana WebSocket and webhook APIs
Carbium RPC pushes Solana data to you two ways: WebSocket subscriptions on every plan, and signed webhooks to your own HTTPS address from Dev at $20 a month. Start with the choice: polling, a socket, a webhook or Carbon Stream.
WebSocket
8 methods
Subscribe to slots, accounts, programs, logs, signatures and blocks
Webhooks
1 credit
Per delivered event. Failed tries and setup calls are free
On Free
5 sockets
WebSocket is on every plan, from $0. Webhooks start on Dev
01 · Choose
Polling, WebSocket, webhook or Carbon Stream?
All four tell your code that something happened on Solana. They differ in who starts the conversation, what has to stay running, and what happens while you are away.
JSON-RPC over HTTPSPolling
Your code asks on a timer and gets the state at that moment. Every poll is a request, whether anything changed or not.
Carbium RPCSubscriptions over WSSWebSocket
You open one socket and Carbium RPC pushes each change down it while it stays open. After a drop nothing is replayed.
How subscriptions workSigned HTTPS POSTWebhook
Carbium calls you: a finalized transaction that touches an address you listed is posted to your server, and tried again if it does not answer.
How webhooks workYellowstone gRPCCarbon Stream
A filtered gRPC stream of whole transactions, accounts and slots, for services that read the chain all day. From the Dev plan, on the same key.
Carbon Stream
- A balance or a status on a page that people reload
- One request when the page opens is enough. Poll only while someone is looking.
- Polling
- A screen that changes the moment the chain does
- One socket, and a subscription for each account or address you show.
- WebSocket
- Knowing that the transaction you just sent has landed
signatureSubscribebefore you send. It notifies once and ends itself.- WebSocket
- Deposits or payments to addresses you own
- Nothing to keep connected: a delivery your server misses is tried again for about 27 hours.
- Webhook
- Alerts for thousands of user wallets
- One webhook watches up to 100,000 addresses on Pro. A socket takes a subscription for each.
- Webhook
- Every transaction of a program, in your own database
- The whole transaction is pushed, filtered by the accounts you name, and a restart can resume from a recent slot. A socket filters on one address per subscription and replays nothing.
- Carbon Stream
02 · WebSocket
WebSocket subscriptions on Carbium RPC
Solana's own subscription protocol on wss://services.carbium.sh, with the key you already use for JSON-RPC. web3.js, Kit and any WebSocket client connect by changing the URL.
slotSubscribe- Each new slot.
- 5
rootSubscribe- Each new root.
- 5
signatureSubscribe- One notification when a transaction reaches the commitment you asked for. Then it ends.
- 5
accountSubscribe- An account's state when it changes. Token accounts and accounts of the covered programs notify; a plain SOL wallet under 1,000,000 SOL stays silent.
- 25
logsSubscribe- The logs of every transaction, or of those that mention one address. Failed transactions are included.
- 25 with a mention, 200 for all
slotsUpdatesSubscribe- Each step of a slot's life.
- 25
programSubscribe- Account changes under a program, for a covered set: SPL Token, Token-2022 and the main pool programs among them.
- 200
blockSubscribe- Each new block, or only the blocks with a transaction that mentions one address.
- 200
finalized unless you set it. Every option, error and close code: the WebSocket skill file.Not served, and what to use instead
transactionSubscribeis not served. UselogsSubscribewith one address inmentions, or a Carbon Stream transaction filter.- A plain SOL wallet stays silent on
accountSubscribe. Subscribe to its logs and readgetBalance, as the example further down does. programSubscribeoutside the covered set answers-32010and is not charged. UselogsSubscribewith the program as the mention.- JSON-RPC methods such as
getSlotdo not run over the socket. Send them over HTTPS.
// One socket, one subscription: every new slot, pushed to you.
// Node 22 and browsers have WebSocket built in.
const url = "wss://services.carbium.sh/?api-key=" + process.env.CARBIUM_KEY;
const ws = new WebSocket(url);
ws.onopen = () =>
ws.send(JSON.stringify({ jsonrpc: "2.0", id: 1, method: "slotSubscribe" }));
ws.onmessage = (event) => {
const msg = JSON.parse(event.data);
if (msg.id === 1)
return console.log("subscription", msg.result ?? msg.error);
if (msg.method === "slotNotification")
console.log("slot", msg.params.result.slot);
};
ws.onclose = (event) => console.log("closed", event.code, event.reason);
api-key. followed by the key, and it stays out of the URL. Give a key that ships to a browser the WebSocket scope only.03 · Reconnect
Keep a socket alive, and recover when it drops
A socket will drop: a deploy, a network change, a closed laptop. Subscriptions do not survive it and nothing is replayed, so a client has four jobs.
Reconnect with backoff
Start at half a second and double up to 30 seconds, with jitter. Stop on close code
1008: the key or the credits ran out while connected. A handshake refused at the start (the key, the connection cap or the rate) closes with1006before any open, so check the key and your open sockets if the first connect never opens.Subscribe again
Subscription ids belong to one connection. Send every subscribe again and map the new ids.
Read what you missed
Read the state again over JSON-RPC, with
getAccountInfoorgetSignatureStatuses, before you trust new notifications.Read fast
A socket whose queue fills is closed with
1013 slow_consumer. Do less per message, or split subscriptions over more sockets.
// A socket that comes back: reconnect with backoff, subscribe again,
// and read over HTTPS what you missed. Nothing is replayed.
const URL = "wss://services.carbium.sh/?api-key=" + process.env.CARBIUM_KEY;
const WANT = [{ method: "slotSubscribe" }]; // every subscription you need
let wait = 500;
function connect() {
const ws = new WebSocket(URL);
const live = new Map(); // this connection's ids: they change every time
ws.onopen = () => {
wait = 500;
WANT.forEach((sub, id) =>
ws.send(JSON.stringify({ jsonrpc: "2.0", id, ...sub })));
};
ws.onmessage = (event) => {
const msg = JSON.parse(event.data);
if ("id" in msg) {
if (msg.error) return console.error(msg.error.message);
live.set(msg.result, WANT[msg.id]);
return console.log("live", WANT[msg.id].method, "as", msg.result);
}
const sub = live.get(msg.params.subscription);
if (sub) console.log(sub.method, JSON.stringify(msg.params.result));
};
ws.onclose = (event) => {
console.error("closed", event.code, event.reason);
// 1008: the key or the credits, while connected. A person has to fix
// that, a loop cannot. A refused handshake closes with 1006.
if (event.code === 1008) return;
setTimeout(connect, wait + Math.random() * 250);
wait = Math.min(wait * 2, 30000);
};
}
connect();
Three figures behind every socket
1,000 subscriptions a socket
Open one socket and reuse it. Open a second only past that, inside your plan's connection cap.
A ping every 30 seconds
The server pings, and closes a socket that has not answered for 300 seconds. Browsers, Node 22 and the
wspackage answer for you.One address per mention
logsSubscribetakes one address inmentions. Use one subscription per address.
04 · Webhooks
Webhooks: a signed POST per finalized transaction
Give Carbium an HTTPS address and a list of Solana addresses. A finalized transaction that touches one of them is posted to you, signed, with no socket to hold open. On Dev, Business and Pro.
Create it
On the dashboard's Webhooks tab, or with one API call: a key, your HTTPS address and the addresses to watch. A program id counts as an address, and
tx_statusnarrows it to successful or failed transactions. The signing secret is shown once, so store it.Receive
One POST per transaction: a JSON array of one, in the shape
getTransactionreturns. A body over 64 KB arrives in a short form with the signature, and you read the rest withgetTransaction.Verify
Check the HMAC-SHA256 signature over the raw body with your secret, before you parse it. Refuse a timestamp more than five minutes off.
Answer, then work
Answer 2xx within 15 seconds and do the work after. A redirect is not followed and counts as a failed try.
// receive.mjs: check the signature on the raw body, answer 200, then work.
import { createServer } from "node:http";
import { createHmac, timingSafeEqual } from "node:crypto";
function verify(secret, headers, raw) {
const id = headers["webhook-id"], ts = headers["webhook-timestamp"];
if (!secret || !id) return false;
// refuse a stamp more than 5 minutes from this clock
if (!(Math.abs(Date.now() / 1000 - Number(ts)) <= 300)) return false;
const key = Buffer.from(secret.slice("whsec_".length), "base64");
const mac = createHmac("sha256", key).update(id + "." + ts + ".");
const want = Buffer.from("v1," + mac.update(raw).digest("base64"));
const sent = String(headers["webhook-signature"] || "").split(" ");
return sent.some((sig) => {
const got = Buffer.from(sig);
return got.length === want.length && timingSafeEqual(got, want);
});
}
const seen = new Set(); // use a database in production
createServer((req, res) => {
const parts = [];
req.on("data", (chunk) => parts.push(chunk)).on("end", () => {
const raw = Buffer.concat(parts);
if (!verify(process.env.WHSEC, req.headers, raw))
return res.writeHead(401).end();
res.writeHead(200).end(); // inside 15 seconds, before the work
const id = req.headers["webhook-id"];
if (seen.has(id)) return; // a retry of an event you already have
seen.add(id);
for (const tx of JSON.parse(raw)) {
const signature = tx.transaction?.signatures[0] ?? tx.signature;
if (tx.test) console.log("test event");
else console.log(tx.slot, signature);
}
});
}).listen(8080); // behind your HTTPS name on port 443
What a delivery promises
At least once, in no order
A delivery can repeat, and deliveries are not ordered. Skip a
webhook-idyou have seen, and sort byslotwhere order matters.8 tries over about 27 hours
After 5 seconds, 5 minutes, 30 minutes, then 2, 5, 10 and 10 hours. Meanwhile up to 10,000 events or 64 MiB wait per webhook. Past that the oldest are dropped, and so is an event after its last try. A webhook takes at most 200 transactions of one slot.
Off after 5 days
A webhook whose every try fails for 5 days is switched off. Fix the receiver, send a test event, then switch it back on.
Not offered
- Parsed payloads. The body is the raw transaction, in the shape a Helius raw webhook sends.
- Account-change webhooks. A webhook fires on transactions.
- Batches. One transaction per POST.
- Replay of past events. Read them with
getSignaturesForAddressandgetTransaction. - Delivery to Discord.
- The System, Token, Token-2022, Associated Token, ComputeBudget and Vote programs as watched addresses.
05 · Limits
WebSocket and webhook limits on every plan
Limits are per account, and all of an account's keys share them. The prices are read from carbium.sh.
| Limit | Free | Dev | Business | Pro |
|---|---|---|---|---|
| Per month | $0 | $20 | $250 | $500 |
| WebSocket connections | 5 | 150 | 250 | 1,000 |
| Subscriptions across them | 10 | 5,000 | 20,000 | 50,000 |
| Webhooks | Not included | 5 | 25 | 50 |
| Addresses per webhook | Not included | 1,000 | 25,000 | 100,000 |
| Deliveries a second | Not included | 10 | 50 | 200 |
| Carbon Stream streams | Not included | 5 | 25 | 100 |
06 · Example
Watch a wallet, start to finish
The job most apps start with, and the one place where the obvious subscription stays silent.
Subscribe to its logs
logsSubscribewith the wallet as the one mention fires for every transaction that names it, failed ones included. It costs 25 credits to open.Read the balance
On each notification, read
getBalanceover HTTPS. A plain SOL wallet sends nothing onaccountSubscribe, so this pair is the way.Add its tokens
Token accounts do notify. Add an
accountSubscribefor each one you show, on the same socket.Put the backend on a webhook
For alerts while nobody has the app open, list the same wallet on a webhook, from Dev. A delivery your server misses, during a restart say, is tried again for about 27 hours.
// Watch one wallet: a notification for every transaction that names it,
// then its SOL balance over HTTPS.
const KEY = process.env.CARBIUM_KEY;
const opts = { commitment: "confirmed" };
const WALLET = "YOUR_WALLET_ADDRESS";
const rpc = (method, params) =>
fetch("https://services.carbium.sh", {
method: "POST",
headers: { "content-type": "application/json", "x-api-key": KEY },
body: JSON.stringify({ jsonrpc: "2.0", id: 1, method, params }),
}).then((res) => res.json());
const ws = new WebSocket("wss://services.carbium.sh/?api-key=" + KEY);
ws.onopen = () =>
ws.send(JSON.stringify({
jsonrpc: "2.0", id: 1, method: "logsSubscribe",
params: [{ mentions: [WALLET] }, opts],
}));
ws.onmessage = async (event) => {
const msg = JSON.parse(event.data);
if (msg.method !== "logsNotification") return;
const { signature, err } = msg.params.result.value;
const balance = await rpc("getBalance", [WALLET, opts]);
// a refused or failed read carries an error and no result
if (!balance.result) return console.error("getBalance", balance.error);
const sol = balance.result.value / 1e9;
console.log(signature, err ? "failed" : "ok", sol, "SOL");
};
Where to go next
The streams, the plans and the references this page draws on.
gRPC
Carbon Stream
Whole transactions over Yellowstone gRPC, filtered, with a resume from a recent slot.
Solana gRPC streaming
Plans
Pricing and limits
Every plan's credits, request rates, sockets and streams, side by side.
Carbium RPC pricing
Use case
Data pipelines
Backfill over JSON-RPC, then follow the chain live without a gap.
Carbium for data pipelines
Reference
WebSocket
Every subscription, option and close code, with a full reconnecting client.
carbium.sh/skill
Reference
Webhooks
Every call, field and status, the delivery log and the test event.
carbium.sh/docs
Reference
Rate limits
What each plan allows a second, and what a call past a limit gets.
carbium.sh/docs
Questions
The references on carbium.sh cover every call. For anything else, ask the team on the Carbium Discord.
WebSocket referenceWhat is the difference between a WebSocket and a webhook on Solana?
A WebSocket is a connection your code opens and holds: Carbium RPC pushes notifications down it while it is open, and nothing is replayed after a drop. A webhook is a call Carbium makes to your HTTPS address per finalized transaction that touches an address you listed, tried again for about 27 hours when your server does not answer.
When is polling the better choice?
When a delay of a few seconds is fine, or the job runs on a schedule. A JSON-RPC call needs no open connection and works from anywhere. Move to a subscription once most of your requests only ask whether anything is new.
Carbium RPCWhich Solana WebSocket subscriptions does Carbium RPC serve?
Eight, on wss://services.carbium.sh: slotSubscribe, slotsUpdatesSubscribe, rootSubscribe, accountSubscribe, programSubscribe, logsSubscribe, signatureSubscribe and blockSubscribe. programSubscribe serves a covered set of programs, and accountSubscribe notifies for token accounts and for accounts of those programs.
WebSocket referenceDoes Carbium RPC serve transactionSubscribe?
No. The socket answers it with method not found. Use logsSubscribe with one address in mentions, or a Carbon Stream transaction filter, which pushes the whole transaction.
Carbon StreamWhy does accountSubscribe stay silent for my wallet?
A plain SOL wallet under 1,000,000 SOL is acknowledged but stays silent while it holds SOL, and a subscription that never fired has its credits refunded when it closes. Use logsSubscribe with the wallet as the mention and read getBalance over HTTPS on each notification. Token accounts notify on accountSubscribe directly.
How many WebSocket connections does each plan allow, and what does a subscription cost?
Per account, Free holds 5 connections and 10 subscriptions, Dev holds 150 connections and 5,000 subscriptions, Business holds 250 connections and 20,000 subscriptions, Pro holds 1,000 connections and 50,000 subscriptions. One connection holds up to 1,000 subscriptions. Opening one costs 5, 25 or 200 credits by its weight, then 20 credits per MiB the socket sends you. A refused subscription is not charged.
Compare all plans and limitsWhich plans include webhooks, and what are the caps?
Dev, Business and Pro, from $20 a month. They register 5, 25 and 50 webhooks per account, watch up to 1,000, 25,000 and 100,000 addresses per webhook, and deliver up to 10, 50 and 200 events a second per account. Free has no webhooks. A delivered event costs 1 credit, and so does a delivered test event; a failed try and the calls that create, change or delete a webhook cost nothing.
Rate limits on carbium.shWhat happens to webhook events while my server is down?
A delivery with no 2xx answer within 15 seconds is tried again after 5 seconds, 5 minutes, 30 minutes, 2 hours, 5 hours, 10 hours and 10 hours: 8 tries over about 27 hours. Meanwhile up to 10,000 events or 64 MiB wait per webhook; past that the oldest are dropped, and so is an event after its last try. A webhook whose every try fails for 5 days is switched off until you turn it back on.
Can a webhook send parsed transactions or account changes?
No. Each delivery is one raw transaction in the shape getTransaction returns, as a Helius raw webhook sends it, signed with HMAC-SHA256. Parsed payloads, account-change webhooks, Discord delivery, batching and replay of past events are not offered.
Can I open the socket from a browser?
Yes. A browser cannot set headers, so pass the key as a WebSocket subprotocol, api-key. followed by the key, which keeps it out of the URL. Anyone using the page can read that key, so give it the WebSocket scope only, or hold the socket on your backend.
When should I move from WebSocket to Carbon Stream?
When you need one filter over many accounts, or a restart that resumes from a recent slot. Carbon Stream is native Yellowstone gRPC, on Dev, Business and Pro. A socket filters on one address per subscription and replays nothing.
Carbon Stream: Solana gRPC streamingStart on a socket, add a webhook when you need one
Carbium RPC runs on bare-metal servers Carbium owns in Switzerland. WebSocket subscriptions come with every plan, on the key you use for JSON-RPC. Webhooks and Carbon Stream start on Dev.
Back to Carbium RPC