getBalance

Overview

The getBalance JSON-RPC method is a fundamental query function on the Solana blockchain, specifically designed to retrieve the native SOL (Solana) balance of a given account. It returns the current balance in lamports, the smallest unit of SOL, where 1 SOL equals 1,000,000,000 lamports. This method provides a direct read of an account's lamports field within its AccountInfo structure, without requiring any on-chain transaction or state modification.

Developers primarily use getBalance for client-side applications such as wallets, block explorers, and decentralized applications (dApps) to display a user's current SOL holdings. It is crucial for pre-transaction checks, allowing dApps to verify if an account possesses sufficient SOL to cover transaction fees (rent-exempt or priority fees) or to participate in SOL-denominated activities. Its read-only nature and low latency make it an ideal choice for quickly fetching real-time balance information without impacting network congestion.

The method's importance stems from its role as a basic building block for interacting with the Solana ecosystem. Without it, clients would be unable to ascertain the liquidity of an account, hindering the ability to construct valid transactions or provide accurate financial displays. While it only reports native SOL, it forms the basis for understanding an account's overall financial health when combined with other methods that query SPL token balances or other on-chain assets.

Parameters

| Name | Type | Required/Optional | Description

Usage Examples

TypeScript (Fetch)

1const response = await fetch("http://[IP_ADDRESS]:[PORT]", {
2  method: "POST",
3  headers: {
4    "Content-Type": "application/json",
5  },
6  body: JSON.stringify({
7    jsonrpc: "2.0",
8    id: 1,
9    method: "getBalance",
10    params: [] // Add relevant parameters here
11  }),
12});
13
14const data = await response.json();
15console.log(data);

Python (Requests)

1import requests
2import json
3
4url = "http://[IP_ADDRESS]:[PORT]"
5payload = json.dumps({
6  "jsonrpc": "2.0",
7  "id": 1,
8  "method": "getBalance",
9  "params": [] # Add relevant parameters here
10})
11headers = {
12  'Content-Type': 'application/json'
13}
14
15response = requests.request("POST", url, headers=headers, data=payload)
16print(response.text)

Rust (reqwest)

1use reqwest::Client;
2use serde_json::json;
3
4#[tokio::main]
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6    let client = Client::new();
7    let res = client.post("http://[IP_ADDRESS]:[PORT]")
8        .json(&json!({
9            "jsonrpc": "2.0",
10            "id": 1,
11            "method": "getBalance",
12            "params": [] // Add relevant parameters here
13        }))
14        .send()
15        .await?
16        .text()
17        .await?;
18
19    println!("{}", res);
20    Ok(())
21}