Skip to main content
This guide reads an account’s SOL balance over HTTP. Use a server-side script and an RPC API key from the dashboard.

Call getBalance

Set your API key, then run:
Replace the example address with a wallet or account public key. The response contains result.context.slot and result.value. The value is in lamports, where 1 SOL equals 1,000,000,000 lamports; this method does not return SPL token holdings.

Use Node.js

Use Node.js 20 or later. Save this as balance.mjs and run it with the same environment variable. The helper checks both HTTP errors and JSON-RPC errors, which can be returned with HTTP 200.
balance.mjs
Keep API keys in server-side environment variables. Avoid putting the endpoint URL, including its key, into client bundles or logs.

Choose commitment

  • processed: the node’s most recent processed state; it can be rolled back.
  • confirmed: state voted on by a supermajority of stake. This example uses it for current reads.
  • finalized: state at the strongest commitment level, further behind the chain tip.
Choose the same commitment when comparing related reads. Calls made separately can still return different context slots. Use getMultipleAccounts when you need several account values in one response.

Handle failures

For HTTP 429, reduce concurrency and retry reads with bounded backoff and jitter. Invalid parameters and authentication errors need a request or configuration fix. If a transaction submission times out, check its signature status before deciding how to retry; rebuilding and signing creates a different transaction.

Next steps