---
id: I0143
title: "React Native Kit RPC client"
url: https://carbium.sh/library/integrate/react-native-kit-rpc-client
collection: Integrations
category: Mobile and desktop
revision: 1
updated: 2026-11-23
author: Carbium
code: MIT (LICENSE in the zip); text: all rights reserved, Carbium Corporation
---

# React Native Kit RPC client

A React Native app can build a Carbium RPC client with @solana/kit 8.6.0 and read node health, the current slot and an address balance. The file here runs the same calls under Node 24, with the key in a header and no signing.

## What the check does

This file builds one Carbium RPC client and reads three things from it: node health, the current slot and the lamport balance of one address. It signs nothing and sends nothing. The only secret it needs is the Carbium key, read from `CARBIUM_KEY`.

The client comes from `@solana/kit` 8.6.0 and its default transport, which calls the global `fetch`. React Native provides that global, so the same construction carries over to a mobile app. Pin `@solana/kit` at 8.6.0 and set `type` to `module` in `package.json`, since Node 24 strips the types on load. The file here runs under Node 24 and does not run a React Native build.

Three reads are enough to show that a client works end to end. The node answers a health probe, it reports a slot, and an account returns a balance. Each read touches a different part of the path, so a failure points to where the problem sits.

## One client with the key in a header

Carbium's [RPC endpoint](https://carbium.sh/docs/endpoints) is `https://services.carbium.sh`, and the key goes in the `x-api-key` header, as the [auth page](https://carbium.sh/docs/auth) lists for RPC calls. The endpoint comes from `CARBIUM_RPC_URL` when that is set, and the default is the endpoint above. The file exits with a message when the key is missing and never prints it.

Build the client once and reuse it. [Connections stay open 600 seconds](https://carbium.sh/docs/endpoints) and TLS sessions resume, so one client keeps the connection warm across every read in the app. A new client for each request throws that away.

The same key can also travel as `?api-key=` on the URL, and the [auth page](https://carbium.sh/docs/auth) accepts that form too. A URL tends to land in proxy logs and in device history, so this file keeps the key in the header and out of the address.

## Three reads, settled one by one

The reads run in `Promise.allSettled`, so a failed call prints its own line and the other two still print. Each read names its commitment. The SDK fills in `confirmed` when a call leaves it out, but a balance screen should state the level it shows.

| Call | Commitment sent | What the screen can show |
|---|---|---|
| getHealth | none (no commitment field) | whether the node reports itself healthy |
| getSlot | confirmed | the slot the node has confirmed |
| getBalance | confirmed | the lamport balance, as a bigint |

Lamports come back as `bigint`, and `JSON.stringify` refuses a bigint, so the replacer turns each one into a string before printing. A screen that shows SOL divides the lamport count by 1,000,000,000 and keeps the integer until then.

`getHealth` answers `ok` when the node judges itself healthy, and an error otherwise. `getSlot` answers a number, and `getBalance` answers an object whose `value` field holds the lamports. A SOL balance leaves out token balances, so a wallet that holds only tokens reads 0 here.

## Keep the key off the device

A key inside an app bundle can be read by anyone who unpacks the app. [Limits are per account](https://carbium.sh/docs/limits), so one leaked key spends the budget of every key on that account. The check reads the key from the environment of a machine you run, and a shipped app should not do otherwise.

> Put the key on a server you control, let that server make the Carbium calls, and let the app call your server. Do not place the key in a React Native bundle, in an environment file that ships with the app, or in a public repository.

## Run it and read the output

Run the file with the public address of the Jupiter aggregator program as its one argument, with `CARBIUM_KEY` set in the shell: `node main.ts JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4`. A program account is an ordinary account to `getBalance`, and many transactions touch this one on mainnet.

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

```ts
// I0143 · React Native Kit RPC client
// https://carbium.sh/library/integrate/react-native-kit-rpc-client
// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.
// SPDX-License-Identifier: MIT

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

const apiKey = process.env.CARBIUM_KEY;
if (!apiKey) {
  process.stderr.write("CARBIUM_KEY is not set. Export your key and run again.\n");
  process.exit(1);
}
const addressArg = process.argv[2];
if (addressArg === undefined) {
  process.stderr.write("Pass one base58 address as the first argument.\n");
  process.exit(1);
}
const endpoint = process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh";
const target = address(addressArg);

const transport = createDefaultRpcTransport({
  url: endpoint,
  headers: { "x-api-key": apiKey },
});
const client = createSolanaRpcFromTransport(transport);

type Probe = { label: string; run: () => Promise<unknown> };
const probes: Probe[] = [
  { label: "getHealth", run: () => client.getHealth().send() },
  { label: "getSlot", run: () => client.getSlot({ commitment: "confirmed" }).send() },
  {
    label: "getBalance",
    run: () => client.getBalance(target, { commitment: "confirmed" }).send(),
  },
];

const settled = await Promise.allSettled(probes.map((p) => p.run()));

const stringifyBig = (_key: string, value: unknown) =>
  typeof value === "bigint" ? value.toString() : value;

settled.forEach((outcome, index) => {
  const { label } = probes[index]!;
  if (outcome.status === "fulfilled") {
    process.stdout.write(`${label}: ${JSON.stringify(outcome.value, stringifyBig)}\n`);
    return;
  }
  const reason = outcome.reason;
  const text = reason instanceof Error ? reason.message : String(reason);
  process.stdout.write(`${label} failed: ${text}\n`);
});
```

Three lines print, one for each call, in the order the code sends them. Each value prints as JSON, and a failed call prints its message beside its name while the others still print. Run it with no argument and it prints the usage line and exits before any request leaves.

Pick an address that has transactions in the last few minutes, so the balance line is worth comparing with what an explorer shows for the same account.

## Where it ends

- The check runs under Node 24. It does not run a React Native build, a device or the Hermes engine, so any bundler or polyfill issue in your app is outside what this check shows.
- It reads three values. It does not read account data, token balances or transactions.
- A balance is a reading at one moment. A screen that shows it keeps showing that number until the app asks again.
- Limits are per account, and the file does not retry a 429. The app decides when to wait and when to try again.
- Other reads need their own cost check against the [limits page](https://carbium.sh/docs/limits) before a screen calls them on every refresh.
- It reads only, with no signing and no sending, so a balance on screen says nothing about whether a payment has landed.

## When it goes wrong

| What goes wrong | What to do |
|---|---|
| Every call answers 401 with UNKNOWN_KEY. | The key is not the whole key, or it belongs to another account. Copy the whole key into `CARBIUM_KEY`, as the [errors page](https://carbium.sh/docs/errors) sets out for a 401 at the door. |
| The process throws at `address()` before any request leaves. | The first argument is not a valid base58 address. Copy the public address whole from a wallet or an explorer, and check that nothing else was pasted with it. |
| The print step throws a TypeError saying a BigInt cannot be serialized. | The replacer that turns bigint values into strings was removed or bypassed. Keep it, or convert each lamport value to a string before it reaches `JSON.stringify`. |
| A 429 on getSlot or getBalance when a screen refreshes on a timer. | A call over its rate waits once and is served if its cells refill within 1 second. Past that it gets a 429 with a retry-after hint. Refresh on user action or at a slower interval, and reuse the one client. |
| getBalance returns 0 for a wallet that holds tokens. | That is correct for SOL, because token balances live in token accounts. Read them with their own calls, such as `getTokenAccountsByOwner`, and check their cost on the limits page before a screen refreshes them. |

## Questions

### Can I run this client in React Native without changes?

The transport uses the global `fetch`, which React Native provides, so the construction carries over. The check here runs under Node 24 only, so test the bundle and its polyfills on a device before you rely on it.

### Which commitment should a balance screen use?

Use `confirmed` for a balance a user reads right after an action, and say which level the screen shows. On mainnet a slot is about 200 ms and finalized sits 0 to 1 slots behind processed, so the gap between levels is small.

### Does the app need the key on the phone?

No. Put the key on your own server and have the app call that server, as the section on keeping the key off the device explains.

### Why not stream the balance over a WebSocket?

Plain SOL wallets send nothing over `accountSubscribe`, so a balance that updates on its own pairs [logsSubscribe](https://carbium.sh/docs/websocket) mentions with a `getBalance` read.

## Related

- [First Solana RPC API call](https://carbium.sh/library/howsolana/first-solana-rpc-api-call) (How to use Solana, HS0010)
- [Custom RPC for wallets](https://carbium.sh/library/integrate/custom-rpc-for-wallets) (Integrations, I0002)
- [carbium.sh/docs/endpoints](https://carbium.sh/docs/endpoints)
- [carbium.sh/docs/auth](https://carbium.sh/docs/auth)
- [carbium.sh/docs/limits](https://carbium.sh/docs/limits)
- [carbium.sh/docs/errors](https://carbium.sh/docs/errors)
- [carbium.sh/docs/websocket](https://carbium.sh/docs/websocket)
