# Carbium: Full AI Context > Carbium is full-stack Solana infrastructure on self-owned hardware in Switzerland. > One key and one domain, `services.carbium.sh`, for Carbium RPC (JSON-RPC), Standard WebSocket (pubsub), > Carbon Stream (gRPC, Yellowstone) and the Carbium Swap API for quotes and unsigned swap transactions. > Built for developers who need production-grade performance from day one. > > This file is the short form. The full reference for the service is published by carbium.sh: > https://carbium.sh/docs, https://carbium.sh/skill.md and https://carbium.sh/llms.txt. Where they differ, they win. Keys made before carbium.sh keep working on the endpoints of the service before it, until those plans run out. The pages for those older keys are marked at https://carbium.io/docs/. --- ## Products & Endpoints | Product | Endpoint | Purpose | |---------|----------|---------| | Carbium RPC | https://services.carbium.sh | Solana JSON-RPC reads and writes (mainnet) | | Standard WebSocket | wss://services.carbium.sh | Native Solana pubsub (account, program, logs, signature, slot, root, slot updates, block) | | Carbon Stream (gRPC) | https://services.carbium.sh:9443 | Yellowstone gRPC stream of slots, accounts, transactions, transaction statuses, blocks, block metadata and entries, filtered on the server | | Carbium Swap API | https://services.carbium.sh | Quotes and unsigned swap transactions across Solana liquidity; your app signs and submits. Swaps built with it pay a 0.05% on-chain router fee. JSON-RPC methods `quote`, `swap`, `prices`, `health` on the RPC endpoint | | Carbium Swap | https://dex.carbium.io | Swap app built on the Swap API. Carbium Swap is non-custodial: you connect your own wallet and sign every transaction yourself, except the scheduled buys of a DCA you opened | | Reference | https://carbium.sh/docs | Full reference: endpoints, auth, limits, every error | Reference sections: [endpoints](https://carbium.sh/docs#endpoints), [auth](https://carbium.sh/docs#auth), [limits](https://carbium.sh/docs#limits), [account](https://carbium.sh/docs#account). --- ## Keys & Auth One key covers every plane. Sign in on https://carbium.sh/ to get it. ```env CARBIUM_KEY=your_full_key_here ``` - Send the FULL raw key (`c_serv_...`). The short prefix the dashboard lists (`c_serv_` plus four characters) is a label and is refused as `unknown api key`. - RPC and the Swap API: header `x-api-key` (preferred), or `?api-key=` on the URL. - WebSocket: header `x-api-key`, or `?api-key=` on the URL. Browsers: the subprotocol `api-key.`. - Carbon Stream: gRPC metadata `x-token`. `x-api-key` and `?api-key=` are not read on the stream. What a new key needs before each plane answers: | Plane | Needs | |---|---| | RPC, WebSocket | Nothing more: the starter key covers both | | Carbon Stream | A paid plan, and the gRPC scope turned on for the key (dashboard, Keys, SCOPE) | | Swap API | The Quote module added to the account (it has a free plan), and the quote scope on the key | Plans: https://carbium.sh/ and https://carbium.sh/v1/plans. Limits: https://carbium.sh/docs#limits. **Security rules:** - Never embed keys in frontend/client-side code - Never commit keys to version control - Rotate keys regularly - Prefer a header over the URL forms so the key stays out of logs --- ## Use Case → Product Mapping | Use case | Products needed | |----------|----------------| | Read account data / balances | RPC | | Send a transaction | RPC | | Build a wallet app | RPC + WSS + Swap API | | Get a token swap quote | Swap API | | Build a swap transaction programmatically | Swap API | | Real-time wallet balance updates | Standard WSS (logsSubscribe with mentions, then getBalance over RPC; accountSubscribe for token accounts) | | Transaction confirmation (no polling) | Standard WSS (signatureSubscribe) | | Program account monitoring (pool state) | Standard WSS (programSubscribe) | | Log-based event indexing | Standard WSS (logsSubscribe) | | Slot / block clock / liveness monitoring | Standard WSS (slotSubscribe) | | Full-block streaming | Standard WSS (blockSubscribe), or RPC getBlock | | Index all transactions for a program | Carbon Stream | | Monitor a specific wallet (all activity) | Carbon Stream (transactions with accountInclude) | | Portfolio tracker | RPC | --- ## 1. RPC: Solana JSON-RPC Standard Solana JSON-RPC 2.0 over `POST https://services.carbium.sh`. Put `"method"` before `"params"`. Send `"maxSupportedTransactionVersion": 1` on `getTransaction` and `getBlock`: mainnet carries version-1 transactions. Full reference: https://carbium.sh/docs#rpc ### curl ```bash curl https://services.carbium.sh \ -H 'content-type: application/json' \ -H "x-api-key: $CARBIUM_KEY" \ -d '{"jsonrpc":"2.0","id":1,"method":"getSlot"}' ``` ### TypeScript (@solana/web3.js v1) ```typescript import { Connection, PublicKey } from "@solana/web3.js"; const KEY = process.env.CARBIUM_KEY!; const connection = new Connection("https://services.carbium.sh", { commitment: "confirmed", httpHeaders: { "x-api-key": KEY }, // key stays out of the URL wsEndpoint: "wss://services.carbium.sh/?api-key=" + KEY, // web3.js derives ws from http, so set it }); const slot = await connection.getSlot(); const info = await connection.getAccountInfo(new PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v")); ``` ### Commitment levels - `processed`: fastest, rollback risk - `confirmed`: recommended default for reads - `finalized`: guaranteed, slowest; use it for history you will cache --- ## 2. Standard WebSocket: Solana Pubsub Native Solana subscription protocol on `wss://services.carbium.sh`, same key as RPC. Only the subscribe and unsubscribe methods below (and `getVersion`) work over the socket; send every other method to RPC over HTTPS. Full reference: https://carbium.sh/docs#websocket ### WSS vs Carbon Stream: When to Use Which **Rule of thumb:** watching specific accounts, signatures, logs or slots → WSS (JSON-RPC over WebSocket). Server-filtered transactions and accounts for programs or wallets you name → Carbon Stream (gRPC over HTTP/2; there is no WebSocket form of the stream). ### Subscription Methods | Subscribe / Unsubscribe | Streams | |---|---| | `accountSubscribe` / `accountUnsubscribe` | Account data changes (accounts the node carries; a plain SOL wallet stays silent: use `logsSubscribe` with `mentions` plus `getBalance`) | | `programSubscribe` / `programUnsubscribe` | Accounts owned by a covered program | | `logsSubscribe` / `logsUnsubscribe` | Transaction logs (`"all"`, `"allWithVotes"` or `{"mentions":[one address]}`) | | `signatureSubscribe` / `signatureUnsubscribe` | One confirmation, then the subscription ends itself | | `slotSubscribe` / `slotUnsubscribe` | New slots | | `rootSubscribe` / `rootUnsubscribe` | Rooted slots | | `slotsUpdatesSubscribe` / `slotsUpdatesUnsubscribe` | Slot lifecycle events | | `blockSubscribe` / `blockUnsubscribe` | Blocks (`"all"` or `{"mentionsAccountOrProgram": pubkey}`); always send `"maxSupportedTransactionVersion": 1` | ### TypeScript: slotSubscribe (Node 22+ global WebSocket) ```typescript const ws = new WebSocket("wss://services.carbium.sh/?api-key=" + process.env.CARBIUM_KEY); ws.onopen = () => ws.send(JSON.stringify({ jsonrpc: "2.0", id: 1, method: "slotSubscribe" })); ws.onmessage = (e) => { const m = JSON.parse(e.data); if (m.id === 1) return m.error ? console.error(m.error) : console.log("sub id", m.result); if (m.method === "slotNotification") console.log(m.params.result.slot); }; ws.onclose = (e) => console.log("closed", e.code, e.reason); // see the close-code table ``` ### Reconnection (Required for Production) - Reuse one socket for many subscriptions. Route notifications by `params.subscription`, not by your request `id`. - Subscription ids are not stable across connections. After any reconnect, resubscribe everything and map the new ids. - Nothing is replayed. After a disconnect, re-read the state you care about over RPC. - Reconnect with exponential backoff and jitter. Answer server pings (browsers, Node 22+ `WebSocket` and the `ws` package do it for you). - Close codes and a full reconnecting client: https://carbium.sh/docs#websocket --- ## 3. Swap API: Quotes and Swap Transactions JSON-RPC 2.0 methods on the RPC endpoint, `POST https://services.carbium.sh`, same key carriers as RPC. There are no REST paths. Methods: `quote`, `swap`, `prices`, `health`. Send one call per HTTP request (never batched). - `quote` params: `src_mint`, `dst_mint`, `amount_in` (base units, as a decimal string), `slippage_bps`. The result carries `quoteId`. - `swap` params: `quote_id` and `user_pubkey`, within 30 s of the quote. The result carries one unsigned `transaction` (base64), plus `lastValidBlockHeight` and `minAmountOut`. - Sign it as `user_pubkey` only and never modify it. Send it with `sendTransaction` and `skipPreflight: true`, then confirm with `getSignatureStatuses`. - Any `platformFee` is already inside `destAmountOut` and `minAmountOut`. The swap result's `rentLamports` is an upper bound on the rent for token accounts the swap creates (refundable when they are closed). - HTTP 200 can carry an `error`: read `error.code` too. Full reference: [quote](https://carbium.sh/docs#quote), [swap](https://carbium.sh/docs#swap). ### TypeScript: quote, then swap, sign, send, confirm ```typescript import fs from "node:fs"; import { Keypair, VersionedTransaction } from "@solana/web3.js"; const DOOR = "https://services.carbium.sh"; const KEY = process.env.CARBIUM_KEY!; // the full key, never the short c_serv_ prefix async function call(method: string, params: unknown) { const r = await fetch(DOOR, { method: "POST", headers: { "content-type": "application/json", "x-api-key": KEY }, body: JSON.stringify({ jsonrpc: "2.0", id: 1, method, params }), }); const j = await r.json(); if (j.error) throw Object.assign(new Error(`${method} ${j.error.code}: ${j.error.message}`), { http: r.status, data: j.error.data }); return j.result; } // The wallet that signs: a solana-keygen JSON file, never sent to Carbium const wallet = Keypair.fromSecretKey(Uint8Array.from(JSON.parse(fs.readFileSync(process.env.WALLET_PATH!, "utf8")))); // 1. Quote (0.01 SOL to USDC) const q = await call("quote", [{ src_mint: "So11111111111111111111111111111111111111112", dst_mint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", amount_in: "10000000", slippage_bps: 50, }]); // 2. Swap within 30 s: one unsigned transaction const s = await call("swap", [{ quote_id: q.quoteId, user_pubkey: wallet.publicKey.toBase58() }]); // 3. Sign as user_pubkey only, send with skipPreflight: true const tx = VersionedTransaction.deserialize(Buffer.from(s.transaction, "base64")); tx.sign([wallet]); const wire = Buffer.from(tx.serialize()).toString("base64"); const sig = await call("sendTransaction", [wire, { encoding: "base64", skipPreflight: true }]); // 4. Confirm, or stop once the block height passes lastValidBlockHeight (then quote again) for (;;) { const { value: [st] } = await call("getSignatureStatuses", [[sig]]); if (st?.err) throw new Error("failed on chain: " + JSON.stringify(st.err)); // Custom 6004 = under the slippage floor: quote again if (st?.confirmationStatus === "confirmed" || st?.confirmationStatus === "finalized") break; if ((await call("getBlockHeight", [{ commitment: "confirmed" }])) > s.lastValidBlockHeight) { const { value: [last] } = await call("getSignatureStatuses", [[sig], { searchTransactionHistory: true }]); if (last?.confirmationStatus && !last.err) break; throw new Error("expired: quote again, never re-sign the old message"); } await new Promise((r) => setTimeout(r, 1000)); } console.log("confirmed", sig, "got at least", s.minAmountOut); ``` --- ## 4. Carbon Stream (gRPC) Yellowstone gRPC stream on `https://services.carbium.sh:9443` (TLS), method `geyser.Geyser/Subscribe`, key as `x-token` metadata. It needs a paid plan and the gRPC scope on the key. There is no WebSocket form of the stream. Full reference: https://carbium.sh/docs#stream - Send the subscribe request with the open: a stream with no request within 10 s is closed. The first request fixes the filters for the stream's life; to change them, open a new stream. - Account filters name their accounts (`account: [...]`). To follow a wallet, use `transactions` with `accountInclude`, not `accounts`. - No startup snapshot: load current state over RPC first, then apply stream updates. - Ping every 10 s on the stream and set the client's max receive size to at least 64 MiB. - With `@triton-one/yellowstone-grpc` v5 and later, pass the request to `client.subscribe(request)`. ### TypeScript (@triton-one/yellowstone-grpc v8) ```typescript // npm i @triton-one/yellowstone-grpc@8 @solana/kit import Client, { CommitmentLevel } from "@triton-one/yellowstone-grpc"; import { getBase58Decoder } from "@solana/kit"; const ENDPOINT = "https://services.carbium.sh:9443"; const KEY = process.env.CARBIUM_KEY!; // full key, never the c_serv_xxxx prefix const b58 = getBase58Decoder(); // Every map and list must be present (the TS type requires it); empty ones are not sent on the wire. const EMPTY = { accounts: {}, slots: {}, transactions: {}, transactionsStatus: {}, blocks: {}, blocksMeta: {}, entry: {}, accountsDataSlice: [], blockFooter: {} }; const REQUEST = { ...EMPTY, commitment: CommitmentLevel.CONFIRMED, transactions: { pool: { vote: false, failed: false, accountExclude: [], accountRequired: [], accountInclude: ["675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8"] } }, }; const client = new Client(ENDPOINT, KEY, { grpcMaxDecodingMessageSize: 64 * 1024 * 1024 }); await client.connect(); const stream = await client.subscribe(REQUEST); // a refused key throws here; other refusals end the stream const pinger = setInterval(() => stream.write({ ...EMPTY, ping: { id: 1 } }), 10_000); stream.on("data", (u) => { if (u.ping || u.pong) return; if (u.transaction) { const t = u.transaction.transaction; console.log("tx", u.transaction.slot, b58.decode(t.signature), t.meta?.err ? "failed" : "ok"); } }); stream.on("error", (e) => { clearInterval(pinger); console.error(e); }); // reconnect with backoff, see the reference stream.on("end", () => clearInterval(pinger)); ``` A full reconnecting client, with which errors to retry and which to stop on: https://carbium.sh/docs#stream --- ## 5. Migrating from Other Providers ### From Helius / QuickNode / Triton / Alchemy: swap the HTTP and WebSocket URLs Their key forms are read as they stand (the `?api-key=` query, a leading path segment), so only the host and the key change. ```typescript import { Connection } from "@solana/web3.js"; // Before // const connection = new Connection("https://mainnet.helius-rpc.com/?api-key=KEY"); // After const connection = new Connection("https://services.carbium.sh/?api-key=" + process.env.CARBIUM_KEY, { commitment: "confirmed", wsEndpoint: "wss://services.carbium.sh/?api-key=" + process.env.CARBIUM_KEY, // web3.js v1 derives it otherwise: always set it }); ``` Per-provider tables, the stream and other clients: https://carbium.sh/docs#migrate --- ## 6. Production Patterns - Retry only what waiting can fix: a 429, a 5xx on a read, a 503 on the Swap API. Honour `retry-after-ms` (else `Retry-After`), back off exponentially with jitter. Never loop on a 4xx. - Never auto-retry `sendTransaction`. Check `getSignatureStatuses`, and resend the SAME signed bytes until the block height passes `lastValidBlockHeight`. Only then build a new transaction with a fresh blockhash. - `skipPreflight: true` sends at the higher send rate and lower cost; preflight sends are slower. - Reconnect sockets and streams with exponential backoff, resubscribe everything, and re-read state over RPC. - Quote `x-request-id` (RPC) or `x-subscription-id` (Carbon Stream) when you report a problem. The one retry policy for all planes: https://carbium.sh/docs#errors --- ## 7. Error Reference | HTTP | Meaning | Action | |------|---------|--------| | 401 | The key was refused: unknown key (often the short prefix instead of the full key), the plane is not enabled for the key, or the key is suspended, revoked or disabled | Fix the key or its scope on the dashboard. Do not retry unchanged | | 402 | `credits exhausted`: the remaining credits cannot cover the call | Stop. Renew or buy a plan on the dashboard | | 403 | `module not enabled for this account` (Swap API without the Quote module), the caller's IP is not on the key's allowlist, or (WebSocket handshake) the key is not enabled for websocket | Add the Quote module (it has a free plan), add the address, or turn on the plane. Do not retry unchanged | | 429 | Rate limit, capacity, the free budgets, or credits still loading on this node | Wait `retry-after-ms`, then retry with backoff | - Swap API: `-32051` `no route` comes at HTTP 200: act on `error.data.why`, change the pair or size, do not loop. - Carbon Stream errors are gRPC statuses: stop on `UNAUTHENTICATED` and `PERMISSION_DENIED`, retry `RESOURCE_EXHAUSTED` (except credits) and `UNAVAILABLE` with backoff. - Every code, message and action: https://carbium.sh/docs#errors --- ## 8. Architecture Notes - **One door:** every call on every plane passes the same key, rate and credit checks at `services.carbium.sh` before anything serves it. - **Ports:** standard TLS on 443 for RPC, WebSocket and the Swap API; 9443 for Carbon Stream. - **Coverage:** transactions are complete on WebSocket and Carbon Stream; account streams cover the accounts the node carries, listed in the reference. - **Router fee:** paid inside the router instruction of the built transaction, at the quoted bps. - **Hardware:** the nodes run on self-owned hardware in Switzerland. --- ## Common Token Mints | Token | Mint | |-------|------| | SOL (wrapped) | `So11111111111111111111111111111111111111112` | | USDC | `EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v` | | USDT | `Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB` | --- ## Reference Links | Resource | URL | |----------|-----| | Full service reference | https://carbium.sh/docs | | Reference for AI agents | https://carbium.sh/skill.md | | llms.txt (carbium.sh) | https://carbium.sh/llms.txt | | Plans | https://carbium.sh/v1/plans | | Migration guide | https://carbium.sh/docs#migrate | | Carbium docs (incl. pages for older keys) | https://carbium.io/docs/ | | Dashboard and API keys | https://carbium.sh/ | | Blog | https://carbium.io/blog | | Discord | https://discord.gg/82y3FXCqWw | | X / Twitter | https://x.com/carbiumio | | Telegram | https://t.me/Tolysspider |