Call getBalance
Set your API key, then run: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 asbalance.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
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.