---
id: UC0038
title: "Multi-wallet USD net worth"
url: https://carbium.sh/library/usecase/multi-wallet-usd-net-worth
collection: Use cases
category: Portfolio, tax and accounting
revision: 1
updated: 2026-11-22
author: Carbium
code: MIT (LICENSE in the zip); text: all rights reserved, Carbium Corporation
---

# Multi-wallet USD net worth

One read covers SOL, USDC and USDT for every wallet, and a Node script totals them in dollars at a SOL price you give it. It also lists what the total leaves out: other tokens, stake accounts, positions and history.

## What the total is made of

A net worth for a set of wallets is a sum of quantity times price. The quantities sit on chain: lamports in each wallet account and an amount in each token account. The prices do not. A Solana node knows nothing about dollars, so the job splits into a read of balances and a separate price source, and the total is only as good as the weaker half.

The script here covers the half with a firm answer. It values SOL at a price you pass in, and USDC and USDT at one dollar each, the figure a dashboard normally shows for a dollar stablecoin. Other tokens stay out of the sum on purpose: a price guessed for a thin token moves a total further than any balance read does, and a wrong total that looks complete is worse than a smaller one that says what it holds.

## One read for every wallet

A wallet's SOL is the `lamports` field of the wallet account. A wallet's USDC is the amount in its USDC token account, and for an ordinary wallet that account sits at a derived address: the associated token account for the owner, the token program and the mint. The script derives those addresses locally, with no call, and puts every wallet account and every token account into one `getMultipleAccounts` request read at `finalized`. All balances then come from one slot, which the script prints, so the sum never joins a read taken before a transfer to a read taken after it.

`getMultipleAccounts` [charges 10 cells per pubkey](https://carbium.sh/docs#rpc), so a wallet with its two token accounts costs 30 cells and a call of 100 pubkeys costs 1000. A call takes up to 300 pubkeys on Pro, and below Pro the 1024-cell burst caps it at 100. The script therefore accepts 33 wallets, which is 99 pubkeys. For a longer list, loop over slices of 33 and accept one slot per slice. Account reads run at [0.5, 15, 50 and 400 req/s](https://carbium.sh/docs#rpc) on Free, Dev, Business and Pro.

## The script

Run it with wallet addresses and the SOL price in `SOL_USD`. For each wallet it prints the dollar total and its parts, then the sum across wallets. Without `SOL_USD` it prints the SOL amount marked unpriced and totals only the stablecoins. It exits with a message when `CARBIUM_KEY` is unset, signs nothing and sends nothing.

`main.ts` (run: `CARBIUM_KEY=$CARBIUM_KEY SOL_USD=<price> node main.ts <wallet1> <wallet2>`)

```ts
// UC0038 · Multi-wallet USD net worth
// https://carbium.sh/library/usecase/multi-wallet-usd-net-worth
// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.
// SPDX-License-Identifier: MIT

// Read-only: the USD net worth of several wallets from SOL, USDC and USDT, in one getMultipleAccounts call.
import { address, createDefaultRpcTransport, createSolanaRpcFromTransport, getAddressEncoder, getProgramDerivedAddress, isAddress, type Address } 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 TOKEN_PROGRAM = address("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
const ATA_PROGRAM = address("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL");
// Dollar stablecoins, valued at 1 USD each.
const STABLES: [string, string][] = [
  ["USDC", "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"],
  ["USDT", "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"],
];
const stride = 1 + STABLES.length; // the wallet account, then one token account per stablecoin
const max = Math.floor(100 / stride); // a call takes at most 100 pubkeys below Pro
const wallets = process.argv.slice(2);
if (wallets.length === 0 || wallets.length > max || !wallets.every((w) => isAddress(w))) {
  console.error(`Usage: SOL_USD=<price> node main.ts <wallet> [wallet ...] (1 to ${max} valid addresses)`);
  process.exit(1);
}

// Integers throughout: micro-dollars, lamports and base units.
const MICRO = 1_000_000n;
const LAMPORTS = 1_000_000_000n;
const solUsd = Number(process.env.SOL_USD);
const solPrice = solUsd > 0 ? BigInt(Math.round(solUsd * 1e6)) : undefined; // micro-dollars per SOL
const usd = (n: bigint) => `$${n / MICRO}.${String(n % MICRO).padStart(6, "0").slice(0, 2)}`;
const sol = (l: bigint) => `${l / LAMPORTS}.${String(l % LAMPORTS).padStart(9, "0")}`;

const rpc = createSolanaRpcFromTransport(createDefaultRpcTransport({ url, headers: { "x-api-key": key } }));
const enc = getAddressEncoder();
const ata = async (owner: string, mint: string): Promise<Address> => (await getProgramDerivedAddress({
  programAddress: ATA_PROGRAM,
  seeds: [enc.encode(address(owner)), enc.encode(TOKEN_PROGRAM), enc.encode(address(mint))],
}))[0];

const keys: Address[] = [];
for (const w of wallets) keys.push(address(w), ...(await Promise.all(STABLES.map(([, mint]) => ata(w, mint)))));

// One call, one slot, every wallet, read at finalized.
const { context, value } = await rpc
  .getMultipleAccounts(keys, { commitment: "finalized", encoding: "jsonParsed" })
  .send()
  .catch((e: unknown) => { console.error("read failed:", e instanceof Error ? e.message : e); return process.exit(1); });

type Parsed = { parsed?: { info?: { tokenAmount?: { amount: string; decimals: number } } } };
console.log(`slot ${context.slot} at finalized, SOL at ${solPrice === undefined ? "no price (set SOL_USD)" : usd(solPrice)}`);
let total = 0n;
wallets.forEach((w, i) => {
  const lamports = value[i * stride]?.lamports ?? 0n; // null means no account on chain
  let sum = solPrice === undefined ? 0n : (lamports * solPrice) / LAMPORTS;
  const parts = [`${sol(lamports)} SOL${solPrice === undefined ? " unpriced" : ""}`];
  STABLES.forEach(([name], j) => {
    const t = (value[i * stride + 1 + j]?.data as unknown as Parsed | undefined)?.parsed?.info?.tokenAmount;
    const micro = t ? (BigInt(t.amount) * MICRO) / 10n ** BigInt(t.decimals) : 0n;
    sum += micro;
    parts.push(`${usd(micro)} ${name}`);
  });
  total += sum;
  console.log(`${w}  ${usd(sum)}  (${parts.join(", ")})`);
});
console.log(`net worth ${usd(total)} across ${wallets.length} wallets`);
```

Amounts stay integers end to end. A token amount arrives as a base-unit string, is scaled to micro-dollars with `BigInt` and the mint's own decimals, and is turned into a decimal string only when printed. The SOL price is held as micro-dollars per SOL for the same reason. A float is fine for a chart label and wrong for a ledger line that someone will reconcile. For the plain SOL read on its own, see [SOL balances for many accounts](https://carbium.sh/library/howsolana/sol-balances-for-many-accounts).

## Where the prices come from

The script takes the SOL price from the environment so that the balance read stays the only thing it does. In a product the price comes from a source you trust and name, read once per refresh and stored beside the total, so that a figure on screen always carries the price and the time it used. The quote plane on the same RPC endpoint has a [prices method](https://carbium.sh/docs#prices) next to `quote`, `swap` and `health`. Quote calls need a key with the QUOTE scope, and a key without it gets 401 with -32001. The quote plane [spends no credits](https://carbium.sh/docs#limits), because its plan is the meter.

Extending the script to more tokens means one more row in the mint table and one more price. Keep the price as an integer in micro-dollars per whole token, multiply it by the amount in base units, and divide by 10 to the power of the mint's decimals. Price each mint from one source at one moment, and say so on the page, since two sources for one token can differ by more than a day's balance change.

## Keeping the total current

A timer that reruns the read is the simplest design, and one `getMultipleAccounts` call per slice makes the cost easy to predict: 10 cells for each wallet account and each token account, every refresh. Store each result with its slot, and the table of snapshots becomes your own balance history.

For push updates, `accountSubscribe` [stays silent for a plain SOL wallet](https://carbium.sh/docs#websocket): use `logsSubscribe` with a mentions filter plus `getBalance`. A mentions subscription opens at 25 credits and then costs 20 credits per MiB sent. A transfer into an existing token account never mentions the receiving wallet, so open a mentions subscription for each wallet's USDC and USDT token accounts as well, or incoming stablecoins will never trigger a refresh. On any notification read the whole slice again and recompute instead of patching one number.

## Where it ends

- Associated accounts only: a wallet can own more than one token account for one mint, and the script reads the associated one. USDC held in another account is missed. [Wallet token holdings](https://carbium.sh/library/usecase/wallet-token-holdings) lists every token account of a wallet, and its answer can be added to the sum.
- Other tokens, NFTs and LP tokens: they are not read and not priced. The total is SOL plus two stablecoins and is labelled so.
- Stake accounts and lending or pool positions: delegated SOL sits in stake accounts the wallet does not own as balance, and a position in a program lives in that program's accounts. Neither shows up in the wallet's lamports.
- Stablecoin value: one dollar is an assumption. A stablecoin whose market price drifts off one dollar is still counted at one.
- History: the script gives a snapshot. `getSignaturesForAddress` reaches back [30 days at most](https://carbium.sh/docs#migrate) from Carbium's own address index, and an empty page past that is the index's age limit. Each page of signatures costs 50 cells to list, and each `getTransaction` costs 50 more, so a cost basis or a tax report from chain history is a separate, heavier job, and anything older than 30 days has to come from snapshots you stored.
- Exchange balances: coins held at an exchange sit in its own books, and no on-chain address shows them.

## When it goes wrong

| What goes wrong | What to do |
|---|---|
| The total is lower than the wallet's real worth. | The wallet holds USDC or USDT in a token account that is not the associated one, or holds other tokens. List its token accounts with getTokenAccountsByOwner and add them, with a price for each mint. |
| The script prints its usage line and exits when given more than 33 wallets. | Below Pro a call takes 100 pubkeys, and each wallet uses three, so the script stops before any call. Loop over slices of 33 wallets and sum the slices. |
| The SOL part prints as unpriced and the total looks small. | Pass the SOL price in SOL_USD, or read it from your price source before the balance read and keep it as micro-dollars. |
| Totals shift between two refreshes with no transfer in the wallet. | The price moved. Print the price and its time beside each total. |
| Cents drift in a sum of many wallets. | Keep amounts as BigInt base units and micro-dollars, and format only at print time. Never add parsed floats. |
| A key without the QUOTE scope gets 401 with -32001 on the price call. | Give the key the QUOTE scope in the dashboard, and keep balance reads on the same key. |

## Questions

### Can I get a USD figure from the RPC alone?

No. A node returns balances and knows no dollar value. Prices come from a price source: the quote plane's prices method on the same endpoint, or one you choose, applied to integer balances in your own code.

### How many wallets fit in one call?

The script sends 3 pubkeys per wallet, so 33 wallets fit the 100-pubkey cap that applies below Pro. Pro takes up to 300 pubkeys a call, which is 100 wallets at this layout.

### Why does a wallet with USDC show zero USDC?

The script reads the associated token account only. If the wallet keeps USDC in a different token account, or has never held USDC, the read finds nothing at the associated address.

### Does SOL in a stake account count?

No. Delegated SOL sits in a stake account, and the wallet's lamports hold only what is liquid in the wallet account. Read the stake accounts separately if the net worth must include them.

## Related

- [SOL balances for many accounts](https://carbium.sh/library/howsolana/sol-balances-for-many-accounts) (How to use Solana, HS0016)
- [Wallet token holdings](https://carbium.sh/library/usecase/wallet-token-holdings) (Use cases, UC0005)
- [carbium.sh/docs#rpc](https://carbium.sh/docs#rpc)
- [carbium.sh/docs#prices](https://carbium.sh/docs#prices)
- [carbium.sh/docs#limits](https://carbium.sh/docs#limits)
- [carbium.sh/docs#websocket](https://carbium.sh/docs#websocket)
- [carbium.sh/docs#migrate](https://carbium.sh/docs#migrate)
