---
id: HS0010
title: "First Solana RPC API call"
url: https://carbium.sh/library/howsolana/first-solana-rpc-api-call
collection: How to use Solana
category: Client libraries
revision: 1
updated: 2026-11-22
author: Carbium
code: MIT (LICENSE in the zip); text: all rights reserved, Carbium Corporation
---

# First Solana RPC API call

One TypeScript file makes your first Solana RPC calls on Carbium: node health, version, and the current slot at each commitment level, plus the same slot call as a bare HTTP POST. It only reads: no keypair, no signature, no transaction.

## What a call is

The Solana RPC API is JSON-RPC 2.0 over HTTPS. A call is one POST to one URL with a JSON body that names a method and its params. The reply is one JSON object that holds either a `result` or an `error`. There is no session to open and no SDK you have to install. Carbium serves it at `https://services.carbium.sh`, the same domain that carries WebSocket subscriptions, the gRPC stream and quotes. Every call in the file is a read, so it needs no keypair and signs nothing.

The slot call runs twice, once through `@solana/kit` and once as a bare `fetch` POST, so you can see the wire format under the library. The two calls run at different default commitments: kit fills in `confirmed`, and the server applies `finalized`. The run also prints the other difference between them, a `bigint` from kit against a plain number from the raw reply.

## The code

Install `@solana/kit` at 8.6.0, export `CARBIUM_KEY` and run the file with Node 24, which strips TypeScript types on its own. It takes no arguments.

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

```ts
// HS0010 · First Solana RPC API call
// https://carbium.sh/library/howsolana/first-solana-rpc-api-call
// 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,
  isSolanaError,
  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 headers = { "x-api-key": key };
const rpc = createSolanaRpcFromTransport(createDefaultRpcTransport({ url, headers }));

// The same call without a library: one POST, one JSON object back.
async function raw(method: string, params: unknown[] = []): Promise<unknown> {
  const res = await fetch(url, {
    method: "POST",
    headers: { "content-type": "application/json", ...headers },
    body: JSON.stringify({ jsonrpc: "2.0", id: 1, method, params }),
  });
  if (!res.ok) throw new Error(`HTTP ${res.status}, retry-after ${res.headers.get("retry-after")}`);
  const body = (await res.json()) as { result?: unknown; error?: { code: number; message: string } };
  if (body.error) throw new Error(`${body.error.code} ${body.error.message}`);
  return body.result;
}

// A kit call that waits out one HTTP 429 and tries again.
async function once<T>(call: () => Promise<T>): Promise<T> {
  try {
    return await call();
  } catch (e) {
    if (!isSolanaError(e, SOLANA_ERROR__RPC__TRANSPORT_HTTP_ERROR) || e.context.statusCode !== 429) throw e;
    const seconds = Number(e.context.headers.get("retry-after")) || 1;
    console.error(`429: waiting ${seconds}s, then one more try`);
    await sleep(seconds * 1000);
    return call();
  }
}

console.log("health:", await once(() => rpc.getHealth().send()));
const version = await once(() => rpc.getVersion().send());
console.log("version:", version["solana-core"]);

for (const commitment of ["processed", "confirmed", "finalized"] as const) {
  const slot = await once(() => rpc.getSlot({ commitment }).send());
  console.log(`slot ${commitment}: ${slot}`);
}

console.log("slot kit, no commitment:", await once(() => rpc.getSlot().send()));
console.log("slot raw, no commitment:", await raw("getSlot"));
```

The transport sends the key in the `x-api-key` header on every call. A kit call builds a request and sends nothing until you call `.send()`.

The `raw` helper is the whole protocol in a dozen lines: a POST with a JSON body, a check of the HTTP status, and a look at `error` before `result`. The `once` helper retries a kit call one time when the door answers HTTP 429, after sleeping for the `retry-after` seconds. Kit returns a slot as a `bigint`, while the raw JSON gives a plain number.

## Reading the output

| Line | Method | What it tells you |
|---|---|---|
| health | getHealth | The string `ok` while the node considers itself healthy. A node that is behind answers with an error instead. |
| version | getVersion | The `solana-core` field is the software version the node runs. |
| slot processed | getSlot | The newest slot the node has seen, before the cluster has voted on it. |
| slot confirmed | getSlot | The newest slot a supermajority of the cluster has voted on. |
| slot finalized | getSlot | The newest slot the cluster can no longer roll back. |
| slot kit, no commitment | getSlot | Kit fills in a commitment for you: `confirmed`. |
| slot raw, no commitment | getSlot | The server applies its own default: `finalized`. |

Since the Alpenglow switch on mainnet (2026-10-21) a slot lasts about 200 ms, and finalized sits 0 to 1 slots behind processed, where it used to sit about 32 behind. Expect the three slot lines to differ by at most a slot or so. Two of them are often equal. Because each read is a separate request, one read can also come back briefly out of order, with a finalized slot above the processed one printed just before it. Treat each line as a snapshot of the moment it was taken.

> The JSON-RPC server's default commitment is `finalized`, but `@solana/kit` 8.6.0 sends `confirmed` when a call leaves commitment out. Since Alpenglow the slot numbers alone cannot show which level a call used, so the last two lines of the run will not reveal it. Pass `commitment` on every call you keep, so the level is written in your code.

## On Carbium

`getHealth`, `getVersion` and `getSlot` are cheap cached reads, and so are 22 more methods. Each costs 1 cell. The [rate limits](https://carbium.sh/docs#rpc) allow them at 5 requests per second on Free, 30 on Dev, 100 on Business and 500 on Pro. Limits belong to the account, so all keys of one account share a single budget.

A JSON-RPC call can be a single object or a batch of up to 100. A batch is a `fetch` POST of a JSON array, with one `id` per call, and the reply is an array in the same shape. `@solana/kit` has no batch call, so `raw` is the place to start if you want one.

## Calls to try next

Any other read is a change of method name and params, and the cost follows the method.

- `getAccountInfo`, `getMultipleAccounts` and `getTokenAccountBalance` are account reads at 10 cells each. They are allowed at 0.5 per second on Free, 15 on Dev, 50 on Business and 400 on Pro. `getMultipleAccounts` charges 10 cells per pubkey and takes up to 300 (100 below Pro).
- `getTransaction` costs 50 cells. `getSignaturesForAddress` costs 50 cells too, at 0.24 per second on Free, 1.2 on Dev, 100 on Business and 500 on Pro.
- `sendTransaction` costs 20 cells without preflight and 70 with it. It writes to the chain, so it needs a signed transaction and sits outside this file.

[SPL token balance](https://carbium.sh/library/howsolana/spl-token-balance) builds on this file. It derives a token account address offline and reads it with `getTokenAccountBalance`. [Slack slot-lag alerts](https://carbium.sh/library/integrate/slack-slot-lag-alerts) turns the slot read into a recurring check.

## Where it ends

A good run proves three things: the key is accepted, the node answers, and your client parses the reply. It says nothing about how much of your plan you have used, and it does not read any account.

Carbium does not serve every method of the Solana API. A short list answers `-32601`, among them `getTokenLargestAccounts` and `getProgramAccountsV2`. `-32601` means method not found: do not retry it, because the answer will not change.

`getSignaturesForAddress` pages come from Carbium's own address index, which keeps up to 30 days. An empty page past that is the age limit of the index and does not mean you reached the first transaction of the address. History older than 30 days is not served by that method.

A slot number is stale as soon as it prints. At about 200 ms per slot, a value read a second ago is already several slots behind. If a decision depends on freshness, read again at the moment you act, and use one commitment level for the whole decision.

## When it goes wrong

| What goes wrong | What to do |
|---|---|
| The file exits with `Set CARBIUM_KEY to your Carbium API key.` | Export the key in the shell that runs the file, for example `export CARBIUM_KEY=...`. The file reads it from the environment on purpose, so it never sits in source or in a log. |
| Every call fails with an HTTP error from the door. | The key is missing, misspelt, or sent in a place the door does not read. Send it as the `x-api-key` header, as `?api-key=` in the URL, or as `authorization: Bearer`. |
| `TypeError: fetch failed`, or a connection error before any reply. | The URL is wrong or the machine cannot reach it. If you set `CARBIUM_RPC_URL`, check it. Leave it unset to use `https://services.carbium.sh`. |
| HTTP 429 with a retry-after hint. | Wait for the number of seconds in the header and try once more. If it repeats, slow the loop down or move to a plan with a higher ceiling. The [rate limits](https://carbium.sh/docs#rpc) show the ceiling per method and plan. |
| Error -32601 method not found. | Fix the method name, or use another method. A method Carbium does not serve keeps answering -32601, so do not retry it. |
| The three slots look wrong: finalized shows a higher number than processed. | Each read is its own request, and two of them can land on slightly different views of the chain. This is normal. Compare slots with a tolerance of a slot or two, and pick one commitment level per decision. |

## Questions

### Do I need an SDK to call the Solana RPC API?

No. A call is an HTTP POST with a JSON body, and the `raw` helper in the file does it with the global `fetch`. `@solana/kit` adds types, `bigint` handling and a method per call, which is why the file uses both.

### Which commitment should I pass?

`confirmed` suits a number shown to a user. Use `finalized` when the number triggers something you cannot undo, such as crediting a deposit. Since Alpenglow, finalized sits 0 to 1 slots behind processed, so waiting for it costs little.

### Can I put the key in the URL instead of a header?

Yes, as `?api-key=<YOUR_KEY>`. The header keeps the key out of URLs, which end up in logs and browser history, so the file sends the header.

### How many calls per second can I make?

It depends on the method and the plan. The cheap cached reads in this file cost 1 cell each and run at 5 requests per second on Free, 30 on Dev, 100 on Business and 500 on Pro.

## Related

- [SPL token balance](https://carbium.sh/library/howsolana/spl-token-balance) (How to use Solana, HS0001)
- [Slack slot-lag alerts](https://carbium.sh/library/integrate/slack-slot-lag-alerts) (Integrations, I0001)
- [carbium.sh/docs#rpc](https://carbium.sh/docs#rpc)
- [carbium.sh/docs#auth](https://carbium.sh/docs#auth)
- [carbium.sh/docs#endpoints](https://carbium.sh/docs#endpoints)
- [carbium.sh/docs#limits](https://carbium.sh/docs#limits)
- [carbium.sh/docs#errors](https://carbium.sh/docs#errors)
- [carbium.sh/docs#migrate](https://carbium.sh/docs#migrate)
- [carbium.sh/docs#overview](https://carbium.sh/docs#overview)
