> ## Documentation Index
> Fetch the complete documentation index at: https://www.helius.dev/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Use getBalance

> Learn getBalance use cases, code examples, request parameters, response structure, and tips.

The [`getBalance`](https://www.helius.dev/docs/api-reference/rpc/http/getbalance) RPC method is a straightforward way to find out the native SOL balance of any account on the Solana blockchain. It returns the balance in lamports (1 SOL = 1,000,000,000 lamports).

This method is more lightweight than `getAccountInfo` if you *only* need the SOL balance and no other account details.

## Main Use Case

* **Quickly Checking an Account's SOL Holdings:** The primary use is to determine how much SOL an account (wallet, program, etc.) holds.

## Parameters

1. `publicKey` (string, required): The base-58 encoded public key of the account to query.

2. `config` (object, optional): A configuration object with the following fields:
   * `commitment` (string, optional): Specifies the [commitment level](https://www.helius.dev/blog/solana-commitment-levels) to use for the query. Defaults to `finalized`.
     * `finalized`: The node will query the most recent block confirmed by the supermajority of the cluster as having reached maximum lockout.
     * `confirmed`: The node will query the most recent block that has been voted on by a supermajority of the cluster.
     * `processed`: The node will query its most recent block. Note that the block may not be complete.
   * `minContextSlot` (number, optional): The minimum slot that the request can be evaluated at.

## Response

The `result` field of the JSON-RPC response will be an object containing:

* `context` (object):
  * `slot` (number): The slot at which the balance was retrieved.
  * `apiVersion` (string, optional): The RPC API version (may not be present from all nodes).
* `value` (number): The balance of the account in lamports (unsigned 64-bit integer).

If the account does not exist on-chain, `getBalance` will typically return a value of `0` lamports.

## Example: Fetching an Account's Balance

Let's check the SOL balance of the Serum Program V3 ID (`9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin`) on mainnet. This program account itself holds SOL for rent exemption.

**Note:** Replace `YOUR_API_KEY` with your actual Helius API key in the examples below.

```bash curl theme={"system"}
curl https://mainnet.helius-rpc.com/?api-key=YOUR_API_KEY -X POST -H "Content-Type: application/json" -d \
'{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getBalance",
  "params": [
    "9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin"
  ]
}'
```

```javascript JavaScript (using @solana/web3.js) theme={"system"}
const { Connection, PublicKey, LAMPORTS_PER_SOL } = require('@solana/web3.js');

async function checkBalance() {
  const rpcUrl = 'https://mainnet.helius-rpc.com/?api-key=YOUR_API_KEY'; // Replace YOUR_API_KEY
  const connection = new Connection(rpcUrl, 'confirmed');
  const accountPubKey = new PublicKey('9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin');

  try {
    const lamports = await connection.getBalance(accountPubKey);
    const sol = lamports / LAMPORTS_PER_SOL;

    console.log(`Account PubKey: ${accountPubKey.toBase58()}`);
    console.log(`Balance (Lamports): ${lamports}`);
    console.log(`Balance (SOL): ${sol}`);

  } catch (error) {
    console.error('Error fetching balance:', error);
  }
}

checkBalance();
```

```typescript Kit theme={"system"}
import { address, createSolanaRpc } from "@solana/kit";

const rpc_url = "https://mainnet.helius-rpc.com/?api-key=YOUR_API_KEY";
const rpc = createSolanaRpc(rpc_url);

const publicKey = address("83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcri");
const balance = await rpc.getBalance(publicKey).send();

console.log("Account Balance:", balance);
```

```rust Rust theme={"system"}
use anyhow::Result;
use solana_client::nonblocking::rpc_client::RpcClient;
use solana_sdk::{
    commitment_config::CommitmentConfig, native_token::LAMPORTS_PER_SOL, pubkey::Pubkey,
};
use std::str::FromStr;

#[tokio::main]
async fn main() -> Result<()> {
    let client = RpcClient::new_with_commitment(
        String::from("https://mainnet.helius-rpc.com/?api-key=YOUR_API_KEY"),
        CommitmentConfig::confirmed(),
    );

    let pubkey = Pubkey::from_str("83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcri")?;
    let balance = client.get_balance(&pubkey).await?;

    println!("{:#?} SOL", balance / LAMPORTS_PER_SOL);

    Ok(())
}
```

## Developer Tips

* **Simplicity for SOL Balance:** If you only need an account's SOL balance and no other on-chain data (like owner, data, or executable status), `getBalance` is more efficient than `getAccountInfo` as it fetches less data.
* **Non-Existent Accounts:** If an account does not exist on-chain (has never been initialized or had SOL), `getBalance` will return `0`. This can be a quick way to check for account existence if you only care about its SOL balance.
* **Lamports vs. SOL:** Remember that the balance is returned in lamports. You'll need to divide by `LAMPORTS_PER_SOL` (1,000,000,000) to convert it to SOL.
* **Commitment Levels:** The choice of `commitment` can affect how quickly you get the balance and how confirmed that balance is. For most UI display purposes, `confirmed` offers a good balance. For critical financial transactions, `finalized` provides the highest assurance. See [Solana Commitment Levels](https://www.helius.dev/blog/solana-commitment-levels) for detailed information.
* **Batching with `getMultipleAccounts`:** While `getBalance` is for a single account, if you need balances for many accounts, using `getMultipleAccounts` and then extracting the lamport balance from each account's info can be more performant than many individual `getBalance` calls.

## Related Methods

> [card] [getAccountInfo](https://www.helius.dev/docs/api-reference/rpc/http/getaccountinfo.md)
>
> Get full account details including data, owner, and executable status

> [card] [getMultipleAccounts](https://www.helius.dev/docs/api-reference/rpc/http/getmultipleaccounts.md)
>
> Batch fetch multiple accounts in a single request


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.