---
id: I0002
title: "Custom RPC for wallets"
url: https://carbium.sh/library/integrate/custom-rpc-for-wallets
collection: Integrations
category: Switching from another provider
revision: 1
updated: 2026-11-22
author: Carbium
code: MIT (LICENSE in the zip); text: all rights reserved, Carbium Corporation
---

# Custom RPC for wallets

A Node script that tests your Carbium key the way a wallet will use it, in the URL over HTTP and WebSocket, before you paste it into a custom RPC setting, plus what an endpoint can see and get wrong.

## What the custom RPC field takes

Most Solana wallets have a setting for a custom RPC endpoint, usually under network or advanced settings. Names and options differ by wallet, so read yours first. The common shape is one box for an HTTPS URL, sometimes a second for a WebSocket URL, and no place for a header.

Carbium's [RPC endpoint](https://carbium.sh/docs#endpoints) is `https://services.carbium.sh` and its WebSocket endpoint is `wss://services.carbium.sh`. With no header available, the key goes in the URL as [`?api-key=<YOUR_KEY>`](https://carbium.sh/docs#auth), and both endpoints accept it. The two strings to paste are `https://services.carbium.sh/?api-key=<YOUR_KEY>` and `wss://services.carbium.sh/?api-key=<YOUR_KEY>`.

Your own code can send the key in an `x-api-key` header on HTTP instead. A WebSocket client that cannot change the URL can send the subprotocol `api-key.<YOUR_KEY>`. A wallet rarely has either, so the checker tests the URL form.

## What a custom endpoint changes

A wallet reads the chain and sends transactions through one RPC endpoint. A custom endpoint changes who answers those reads and who forwards those sends. It does not change the chain, its fees or when the network confirms a transaction.

A shared public endpoint refuses or delays calls when its shared allowance runs out. Your account has an allowance of its own, shared by all its keys under [per-account limits](https://carbium.sh/docs#limits), and a Free key can still get 429 when its network's shared budget runs out. A wallet that hangs after the switch is often a wallet that has spent that budget.

## The risks, one by one

| Risk | What happens | What to do |
|---|---|---|
| The endpoint sees your addresses | Every balance read and history lookup names an address and comes from your IP, so the operator can link the two. That holds for any endpoint, ours included. | Use an endpoint whose operator you accept seeing that, and a separate key for each wallet. |
| The key sits in the URL | The wallet stores the URL and may keep it in backups or settings screenshots. Whoever holds the key spends your account's shared budget. | Make a key for this wallet only. If the URL leaks, stop using that key and make a new one. |
| A wrong endpoint answers wrongly | A hostile or broken endpoint can report a false balance, an old blockhash or a made-up simulation. It cannot sign, since your keys stay in the wallet and an edited transaction fails its signature check. | Add only a URL you made yourself. The approval screen's simulated result comes from this endpoint too, so check that the transaction came from the site or app you meant to use, and check a large balance on a second source before you act. |
| A URL someone else hands you | A page or message asking you to add an RPC URL asks you to trust a stranger's answers. | Do not add it. |
| The endpoint fails or drops a send | Balances go empty or the wallet errors. A bad endpoint can also decline to forward a transaction you signed, so the wallet says sent and nothing lands. | Know where the wallet's setting is to switch back to its default endpoint. Look a missing signature up on a second source. |

## Check the key before the wallet does

Install with `npm install @solana/kit@8.6.0` and set `"type": "module"` in `package.json`; Node 24 strips the types on load. The script needs `CARBIUM_KEY` and exits with a message when it is unset. It takes a wallet address as its one argument. `CARBIUM_RPC_URL` and `CARBIUM_WS_URL` are optional and default to the two Carbium endpoints.

It only reads and signs nothing. Over HTTP with the header it calls `getHealth`, then `getSlot`, `getLatestBlockhash` and `getBalance` at `confirmed`. It then repeats `getSlot` with the key in the URL, opens a WebSocket with the key in the URL and waits for one slot update, and finally reads five rows of `getSignaturesForAddress`. A failed step prints `FAIL` and the exit code is 1. The key is never printed.

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

```ts
// I0002 · Custom RPC for wallets
// https://carbium.sh/library/integrate/custom-rpc-for-wallets
// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.
// SPDX-License-Identifier: MIT

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

const key = process.env.CARBIUM_KEY;
const owner = process.argv[2];
if (!key || !owner) {
  console.error("Set CARBIUM_KEY and pass a wallet address: node main.ts <address>");
  process.exit(1);
}
const rpcUrl = process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh";
const wsUrl = process.env.CARBIUM_WS_URL ?? "wss://services.carbium.sh";
const commitment = "confirmed"; // kit fills this in when a call leaves it out
const limit = () => ({ abortSignal: AbortSignal.timeout(8_000) });
let failed = 0;

async function step(name: string, run: () => Promise<string>) {
  try {
    console.log(`ok    ${name}: ${await run()}`);
  } catch (err) {
    failed++;
    console.log(`FAIL  ${name}: ${err instanceof Error ? err.message : String(err)}`);
  }
}
// The form a wallet with one text box has to use. The key is never printed.
const withKey = (base: string) => {
  const url = new URL(base);
  url.searchParams.set("api-key", key);
  return url;
};

const rpc = createSolanaRpcFromTransport(
  createDefaultRpcTransport({ url: rpcUrl, headers: { "x-api-key": key } }),
);

await step("getHealth", async () => String(await rpc.getHealth().send(limit())));
await step(`getSlot (${commitment})`, async () => String(await rpc.getSlot({ commitment }).send(limit())));
await step("getLatestBlockhash", async () => {
  const { value } = await rpc.getLatestBlockhash({ commitment }).send(limit());
  return `valid to block height ${value.lastValidBlockHeight}`;
});
await step("getBalance", async () => {
  const { value } = await rpc.getBalance(address(owner), { commitment }).send(limit());
  return `${value} lamports`;
});

await step("api-key in the URL (HTTP)", async () => {
  const res = await fetch(withKey(rpcUrl), {
    method: "POST",
    headers: { "content-type": "application/json" },
    signal: AbortSignal.timeout(8_000),
    body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "getSlot", params: [{ commitment }] }),
  });
  if (!res.ok) throw new Error(`HTTP ${res.status}`);
  const body = (await res.json()) as { result?: number; error?: { message: string } };
  if (body.result === undefined) throw new Error(body.error?.message ?? "no result");
  return `slot ${body.result}`;
});

await step("api-key in the URL (WebSocket slotSubscribe)", () =>
  new Promise<string>((resolve, reject) => {
    const ws = new WebSocket(withKey(wsUrl));
    const timer = setTimeout(() => done(() => reject(new Error("no slot update in 10 s"))), 10_000);
    const done = (finish: () => void) => {
      clearTimeout(timer);
      ws.close();
      finish();
    };
    ws.addEventListener("open", () => ws.send(JSON.stringify({ jsonrpc: "2.0", id: 1, method: "slotSubscribe" })));
    ws.addEventListener("error", () => done(() => reject(new Error("socket error"))));
    ws.addEventListener("message", (ev) => {
      const msg = JSON.parse(String(ev.data)) as { method?: string; params?: { result: { slot: number } }; error?: { message: string } };
      if (msg.error) done(() => reject(new Error(msg.error?.message ?? "refused")));
      else if (msg.method === "slotNotification") done(() => resolve(`slot ${msg.params?.result.slot}`));
    });
  }),
);

await step("getSignaturesForAddress", async () => {
  const rows = await rpc.getSignaturesForAddress(address(owner), { limit: 5, commitment }).send(limit());
  return `${rows.length} rows`;
});

console.log(failed ? `${failed} step(s) failed` : "all steps ok");
process.exitCode = failed ? 1 : 0;
```

An `ok` line for the URL step and for the WebSocket step means the two strings above will authenticate. A `FAIL` line carries the message the call returned.

## What a wallet costs on your plan

A wallet reads when you open it and, depending on the wallet, again on a timer. Those timer reads are mostly cheap cached calls and the activity list's [address signatures](https://carbium.sh/docs#rpc), and the two have very different rates on Free and Dev.

| Plan | Credits | Cheap reads, req/s | getSignaturesForAddress, req/s |
|---|---|---|---|
| Free, $0 | 500K once, at sign-up | 5 | 0.24 |
| Dev, $20 | 10M a month | 30 | 1.2 |
| Business, $250 | 50M a month | 100 | 100 |
| Pro, $500 | 200M a month | 500 | 500 |

`getHealth` and `getSlot` are cheap cached reads at 1 cell each. `getSignaturesForAddress` and `getTransaction` cost 50 cells each, so an activity screen that lists 20 transactions and opens each one costs 50 plus 20 times 50, which is 1,050 cells. Account reads such as `getAccountInfo` and `getTokenAccountBalance` cost 10 cells. Every method has its own cost, so check the ones your wallet calls. For one token balance read, see [SPL token balance](https://carbium.sh/library/howsolana/spl-token-balance).

A wallet that watches for incoming funds over a WebSocket opens subscriptions. A subscription opens at 5, 25 or 200 credits by filter weight and then costs 20 credits per MiB sent. A refused one is free. Connection and subscription counts are capped per account by tier, and [Free carries 5 sockets](https://carbium.sh/docs#websocket).

> `accountSubscribe` stays silent for a plain SOL wallet on Carbium. A wallet that waits on it for incoming SOL will not update live. The pair that works is `logsSubscribe` with mentions plus `getBalance`.

## Where it ends

- Whether your wallet accepts a custom endpoint, and in what form, is the wallet's decision. The checker tests Carbium and does not test the wallet.
- It does not replay your wallet's calls. Eight methods are not served and answer `-32601`, method not found, among them `getTokenLargestAccounts` and `getProgramAccountsV2`. Do not retry them; [check the method](https://carbium.sh/docs#errors) instead.
- `getSignaturesForAddress` reaches back 30 days at most, from Carbium's own address index. An empty page past that is the [index's age limit](https://carbium.sh/docs#migrate) and says nothing about the address's first transaction.
- A custom endpoint does not lift congestion on the network. When the cluster is busy, transactions still compete for blocks.
- The checker confirms that calls answer. It cannot tell whether an answer is true.

## When it goes wrong

| What goes wrong | What to do |
|---|---|
| The wallet saves the URL, then shows zero balances or a connection error. | Run the checker with the same key. If the URL step fails, the string was cut or has a stray space: paste it again with `?api-key=` and the key unbroken. If every step passes, the wallet calls a method or a WebSocket the checker does not cover. Switch back to its default and read the wallet's error text. |
| Calls answer 429 and the wallet keeps retrying. | The account's budget is spent, often by other keys on the same account, since they share one. Wait out the retry-after hint, lower the other traffic, or move to a plan with a [higher rate](https://carbium.sh/docs#limits). [RPC rate-limit alerts](https://carbium.sh/library/usecase/rpc-rate-limit-alerts) tells you when it happens. |
| The WebSocket step fails with `socket error` or `no slot update in 10 s`. | A proxy or firewall on the machine may block WebSocket upgrades. Check that `CARBIUM_WS_URL` is `wss://services.carbium.sh` with no path, and that the key is the one that passed the HTTP steps. |
| Incoming SOL does not show until you reopen the wallet. | The wallet waits on `accountSubscribe`, which stays silent for a plain SOL wallet. Refresh by hand, or keep the wallet's default endpoint for that one. Code you write can use `logsSubscribe` with mentions plus `getBalance`. |
| The activity list is shorter than before, or an old transaction is missing. | `getSignaturesForAddress` is served from a 30-day index. Open the older transaction in an explorer by its signature. |

## Questions

### Can I use a custom RPC node in my wallet to get past a congested public endpoint?

Yes, in a wallet that has a custom RPC setting: you paste a URL that carries your key. It gives you an allowance of your own. It does not change the network, so a busy cluster still affects when transactions land.

### Is it safe to put an API key in the URL?

It is the only way a wallet with one text box can carry it. Treat the URL as a secret, use a key for that wallet alone, and stop using the key if the URL shows up anywhere. Your own code can use the `x-api-key` header instead.

### Can the endpoint take my funds?

No. It never holds your keys, and a changed transaction fails its signature check. It can see your addresses and give wrong data, and the approval screen's simulation comes from it too, so check that the transaction came from the site or app you meant to use and keep only an endpoint URL you made yourself.

## Related

- [RPC rate-limit alerts](https://carbium.sh/library/usecase/rpc-rate-limit-alerts) (Use cases, UC0001)
- [SPL token balance](https://carbium.sh/library/howsolana/spl-token-balance) (How to use Solana, HS0001)
- [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#rpc](https://carbium.sh/docs#rpc)
- [carbium.sh/docs#websocket](https://carbium.sh/docs#websocket)
- [carbium.sh/docs#errors](https://carbium.sh/docs#errors)
- [carbium.sh/docs#migrate](https://carbium.sh/docs#migrate)
