services
Get a key

library / Integrations / I0016

Google Sheets balances

A small Node script reads the wallet column of a Google Sheet you exported as CSV, fetches each SOL balance from Carbium in batches of 50, and prints a CSV you import back into the sheet, with a slot column that dates every row.

By Carbium · Spreadsheets and workspaces · I0016 · updated 2026-11-22

01

What the script does

The script turns a column of wallet addresses in a Google Sheet into a column of SOL balances. You export the sheet as CSV, run one Node file against Carbium, and import the CSV it prints back into the sheet. The file depends on @solana/kit alone and never talks to Google, so it needs no service account, no OAuth consent screen and no Google Cloud project.

StepWhereWhat happens
ExportSheets: File, Download, Comma Separated Valueswallets.csv holds one address per row in column A.
Readnode main.ts wallets.csv > balances.csvOne getMultipleAccounts call per 50 addresses.
ImportSheets: File, Import, Upload, Insert new sheetThe balances arrive on a sheet of their own.
Look up=VLOOKUP(A2, balances!A:C, 3, FALSE)The SOL balance appears next to each label.
02

The Solana side: many accounts in one call

Carbium's RPC endpoint is https://services.carbium.sh. The script builds one client at the start and reuses it for every batch, with the key in the x-api-key header.

getMultipleAccounts takes up to 300 addresses in one call on Pro, and the 1024-cell burst caps a call at 100 below Pro. The script sends 50 at a time. The answer is an array in the order you asked, with null for an address that has no account on chain. A SOL balance is the lamports field of the account, and 1 SOL is 1,000,000,000 lamports. The script prints both numbers, so the sheet can use either, and prints 0 for a null, which is what an address that was never funded holds.

Every answer carries the slot it was read at. The script copies that slot into a slot column, so each row says when it is true. Two batches in one run are two reads and can carry different slots.

03

The sheet side: export, import, look up

Put one address per row in column A and a label in column B. The script reads column A only and skips any cell that is not an address, with a message on stderr, so a header row, a blank line and a note are all safe. An address that appears twice is read once.

File, Download, Comma Separated Values exports the active sheet. After the run, use File, Import, Upload, pick balances.csv and choose Insert new sheet(s). The new sheet takes the file's name, so rename it balances if it differs. Your own sheet keeps its labels and formulas, and one lookup brings the balance across: =VLOOKUP(A2, balances!A:C, 3, FALSE) returns the sol column, and =SUM(balances!C2:C) totals it.

!Keep the API key out of the sheet. Anyone who can open the sheet reads every cell, and a shared sheet shows its wallet list to every viewer. The key lives in the CARBIUM_KEY variable on the machine that runs the script.
04

The script

Install the one dependency with npm install @solana/[email protected] and set "type": "module" in package.json. Node 24 strips the types on load. The file reads CARBIUM_KEY, which is required, and exits with a message when it is unset. CARBIUM_RPC_URL is optional. Each argument is either an address or the path of an exported CSV.

main.ts
// I0016 · Google Sheets balances// https://carbium.sh/library/integrate/google-sheets-balances// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MITimport {  type Address,  createDefaultRpcTransport,  createSolanaRpcFromTransport,  isAddress,  isSolanaError,  SOLANA_ERROR__RPC__TRANSPORT_HTTP_ERROR,} from "@solana/kit";import { existsSync, readFileSync } from "node:fs";const key = process.env.CARBIUM_KEY;if (!key) {  console.error("Set CARBIUM_KEY to your Carbium API key.");  process.exit(1);}const rpc = createSolanaRpcFromTransport(  createDefaultRpcTransport({    url: process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh",    headers: { "x-api-key": key },  }),);// Each argument is an address, or a CSV exported from the sheet with addresses in column A.const cells = process.argv  .slice(2)  .flatMap((arg) => (existsSync(arg) ? readFileSync(arg, "utf8").split(/\r?\n/).map((l) => l.split(",")[0] ?? "") : [arg]))  .map((cell) => cell.trim().replace(/^"|"$/g, ""))  .filter((cell) => cell !== "");const addresses: Address[] = [...new Set(cells.filter(isAddress))];const skipped = cells.filter((cell) => !isAddress(cell)).length;if (addresses.length === 0) {  console.error("Usage: node main.ts <wallets.csv | address ...>");  process.exit(1);}if (skipped > 0) console.error(`skipped ${skipped} cell(s) that are not addresses (a header row counts)`);// One call per batch; a 429 waits for its retry-after hint and tries the same batch again.async function read(batch: Address[]) {  for (let attempt = 1; ; attempt++) {    try {      return await rpc.getMultipleAccounts(batch, { commitment: "finalized", encoding: "base64" }).send();    } catch (e) {      if (!isSolanaError(e, SOLANA_ERROR__RPC__TRANSPORT_HTTP_ERROR) || e.context.statusCode !== 429 || attempt === 3) throw e;      const wait = Number(e.context.headers.get("retry-after")) || 1;      console.error(`429, retrying in ${wait} s`);      await new Promise((r) => setTimeout(r, wait * 1000));    }  }}const SOL = 1_000_000_000n;console.log("address,lamports,sol,slot");for (let i = 0; i < addresses.length; i += 50) {  const batch = addresses.slice(i, i + 50);  const { context, value } = await read(batch);  batch.forEach((address, j) => {    const lamports: bigint = value[j]?.lamports ?? 0n; // null means no account on chain    console.log(`${address},${lamports},${lamports / SOL}.${String(lamports % SOL).padStart(9, "0")},${context.slot}`);  });}

run: node main.ts wallets.csv > balances.csv

05

Run it and refresh the sheet

Export CARBIUM_KEY, then run node main.ts wallets.csv > balances.csv. The CSV goes to stdout and every message goes to stderr, so the redirect leaves a clean file. The first line is the header address,lamports,sol,slot, followed by one line per distinct address.

To check a run before you import it, count the lines: the file should hold one line more than the number of distinct addresses in column A. A run that stops on an error leaves the lines printed so far in the file, so import only a run that ended without one.

To refresh later, run the script again, select the balances sheet, and import with Replace current sheet. The lookups in your main sheet keep working because the columns do not move. You can schedule the run with cron to keep the CSV current on your machine, but the import into Sheets stays a manual step.

06

What it costs against your limits

`getMultipleAccounts` charges 10 cells per address. A batch of 50 costs 500 cells, and a sheet of 200 wallets costs 2,000 cells per run.

PlanAccount reads, req/s
Free0.5
Dev15
Business50
Pro400

Limits are per account, so every key on the account shares one budget. A retry after a 429 resends the whole batch, so the batch size is 50 to keep that resend small. If you want a smaller batch, change the literal 50 in the loop, which appears in both i += 50 and addresses.slice(i, i + 50).

07

Where it ends

  • It reads SOL only. The lamports field is the native balance of an address. Token balances sit in token accounts with addresses of their own, which SPL token balance covers. getTokenAccountBalance is an account read at 10 cells.
  • It does not write to Google. The CSV goes in through the Import menu by hand, or through your own Google tooling. The sheet never refreshes on its own.
  • An address with no account on chain reads as 0, mistyped or not. The script cannot tell a mistyped address from an empty wallet, because many mistyped strings are still valid addresses.
  • A balance is a snapshot at the slot in its row. A wallet that sends or receives after that slot shows its old balance until the next run.
  • It reads no history. getSignaturesForAddress costs 50 cells and reaches back 30 days at most, from Carbium's own address index, and an empty page past that is the index's age limit. A sheet of per-wallet activity needs its own script.
  • It shows no fiat value. A price column is yours to add in the sheet.
08

When it goes wrong

what goes wrongwhat to do
The run stops at once with an HTTP error on the first batch.The key was refused. Check that CARBIUM_KEY holds the key itself and that nothing else has set CARBIUM_RPC_URL. The script sends the key in x-api-key, and Carbium also takes `?api-key=` on the URL.
The log shows 429, retrying in N s twice and then the run stops with an HTTP error carrying status 429.The account's budget is spent, often by app traffic on other keys. Wait and run again, lower the batch size from 50, or move to a plan with a higher account-read rate. Do not import the partial file.
The sol column shows the same small figure for rows you expected to hold tokens.Those are token account addresses. A token account holds lamports for rent and keeps its tokens in its data, so the sol column says nothing about the tokens. Put the wallet address in column A, or read the token balance as described in SPL token balance.
The message skipped 3 cell(s) that are not addresses appears when you expected 1.The header row counts as one. For the others, open the CSV and look for notes, units or labels in column A. The script reads that column only, and an address with a stray character inside it fails the check.
After the import, the sol column holds text and the totals show 0.A spreadsheet locale that writes decimals with a comma reads 1.500000000 as text. Change the locale under File, Settings, or divide the lamports column by 1000000000 with a formula, which needs no decimal point.
09

Questions

How many wallets can one sheet hold?

The script has no row cap. Each run costs 10 cells per distinct address, spread over calls of 50, so your account's account-read rate is the limit.

Can the sheet fetch balances itself with Apps Script?

In principle, yes. Apps Script's UrlFetchApp can POST a JSON-RPC call with the x-api-key header. The key would then live in the script project, readable by every editor of the sheet, so the script here keeps it on your machine.

Why one call for 50 rows and not one call per row?

One batched call saves round trips and reads all 50 addresses at one slot. The cell budget is the same either way, because getMultipleAccounts charges 10 cells per address.

Which commitment do the balances use?

finalized, named in the call, and the slot column shows the exact slot of each batch.