> For the complete documentation index, see [llms.txt](https://docs.coinvera.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.coinvera.io/integration/solana/rpc/getbalance.md).

# getBalance

The `getBalance` RPC method provides a simple and efficient way to retrieve the **native SOL balance** of any account on the Solana blockchain. The balance is returned in **lamports**, where 1 SOL = 1,000,000,000 lamports. Unlike `getAccountInfo`, which returns detailed metadata, `getBalance` is ideal for lightweight balance checks.

***

#### 🎯 Primary Use Case

* **Quick SOL Balance Check**\
  Instantly determine how much SOL an account—such as a wallet or program-owned address—holds.

***

#### 🛠 Parameters

* **`publicKey`** (*string, required*):\
  The base-58 encoded public key of the account to query.
* **`config`** (*object, optional*):\
  Optional fields to control query behavior:
  * `commitment` (*string*):\
    Determines the commitment level for the request:
    * `finalized` *(default)* – Highest level of confirmation.
    * `confirmed` – Recent vote-confirmed block.
    * `processed` – Most recent block (possibly unconfirmed).
  * `minContextSlot` (*number*):\
    Minimum slot at which the query may be evaluated.

**Public Key:** `4UJuvGZ7Ge8H3je63Nsb9ZRNVBAd3CG2ajibnRaVSbw5`

**Sample Request (CoinVera RPC):**

{% tabs %}
{% tab title="Nodejs" %}

```javascript
const fetch = require('node-fetch');

async function getBalance(rpcUrl) {
  try {
    const response = await fetch(rpcUrl, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        jsonrpc: '2.0',
        id: 1,
        method: 'getBalance',
        "params": [
            "4UJuvGZ7Ge8H3je63Nsb9ZRNVBAd3CG2ajibnRaVSbw5"
          ]
      }),
    });

    const data = await response.json();
    
    // Print the exact full response
    console.log('Full RPC Response:');
    console.log(JSON.stringify(data, null, 2));
    
    return data;
  } catch (error) {
    console.error('Error getting health:', error.message);
    return null;
  }
}

// Example usage
const RPC_URL = 'https://rpc.coinvera.io/?x-api-key=your-coinvera-x-api-key';

getBalance(RPC_URL);
```

{% endtab %}

{% tab title="Python" %}

```python
import json
import asyncio
import aiohttp

async def get_balance(rpc_url):
    try:
        payload = {
            "jsonrpc": "2.0",
            "id": 1,
            "method": "getBalance",
            "params": [
                "4UJuvGZ7Ge8H3je63Nsb9ZRNVBAd3CG2ajibnRaVSbw5"
            ]
        }
        
        async with aiohttp.ClientSession() as session:
            async with session.post(
                rpc_url,
                headers={'Content-Type': 'application/json'},
                json=payload
            ) as response:
                data = await response.json()
                
                # Print the exact full response
                print('Full RPC Response:')
                print(json.dumps(data, indent=2))
                
                return data
                
    except Exception as error:
        print(f'Error getting health: {error}')
        return None

# Example usage
async def main():
    RPC_URL = 'https://rpc.coinvera.io/?x-api-key=your-coinvera-x-api-key'
    await get_balance(RPC_URL)

# Run the async function
if __name__ == "__main__":
    asyncio.run(main())
```

{% endtab %}
{% endtabs %}

**Example Response**

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "context": {
      "slot": 355180145,
      "apiVersion": "2.2.7"
    },
    "value": 196248541
  }
}
```

#### 🧠 Developer Tips (with CoinVera)

* **Use `getBalance` for Simplicity**\
  When you only need SOL balance, this method is significantly lighter than `getAccountInfo` and avoids unnecessary data transfer.
* **Account Existence Check**\
  If the account hasn't been initialized on-chain, `getBalance` returns `0`. This makes it a quick way to check if an account exists *for balance purposes only*.
* **Convert Lamports to SOL**\
  Don’t forget: divide the result by `LAMPORTS_PER_SOL` (1,000,000,000) to display balances in SOL.
* **Commitment Strategy**\
  Choose your commitment level based on the application:
  * `confirmed` – Best for UI and general info.
  * `finalized` – Best for financial or high-assurance operations.\
    See Solana’s commitment model for more on consistency vs. speed.
* **Scaling with `getMultipleAccounts`**\
  Need balances for multiple accounts? While `getBalance` only handles one at a time, using `getMultipleAccounts` and extracting lamport balances can be more efficient at scale.
