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

# getBalance

> Returns the balance of the account of provided public key

## Parameters

<ParamField query="pubkey" type="string" required>
  Public key of the account to query (base-58 encoded string)
</ParamField>

<ParamField query="config" type="object" optional>
  Configuration object containing the following optional fields:

  <Expandable title="config fields">
    <ParamField query="commitment" type="string" optional>
      The level of commitment to use:

      * `processed`: Latest block (unconfirmed)
      * `confirmed`: Confirmed by supermajority
      * `finalized`: Finalized by supermajority
    </ParamField>

    <ParamField query="minContextSlot" type="number" optional>
      The minimum slot that the request can be evaluated at
    </ParamField>
  </Expandable>
</ParamField>

## Response

<ResponseField name="result" type="object">
  <Expandable title="result fields">
    <ResponseField name="context" type="object">
      <ResponseField name="slot" type="number">
        The slot the request was processed at
      </ResponseField>
    </ResponseField>

    <ResponseField name="value" type="number">
      Number of lamports assigned to this account
    </ResponseField>
  </Expandable>
</ResponseField>

## Code Examples

### Basic Request

```bash theme={null}
curl https://fra.rpc.orbitflare.com?api_key=YOUR-API-KEY -X POST -H "Content-Type: application/json" -d '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getBalance",
  "params": [
    "83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcri"
  ]
}'
```

### Request with Commitment

```bash theme={null}
curl https://fra.rpc.orbitflare.com?api_key=YOUR-API-KEY -X POST -H "Content-Type: application/json" -d '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getBalance",
  "params": [
    "83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcri",
    {
      "commitment": "finalized"
    }
  ]
}'
```

### Using web3.js

```typescript theme={null}
import { Connection, PublicKey } from '@solana/web3.js';

const connection = new Connection('https://fra.rpc.orbitflare.com?api_key=YOUR-API-KEY');
const publicKey = new PublicKey('83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcri');

const balance = await connection.getBalance(
  publicKey,
  'confirmed'
);

console.log(`Balance: ${balance / 1e9} SOL`);
```

## Notes

1. Balance is returned in lamports (1 SOL = 1,000,000,000 lamports)
2. For new accounts, balance will be 0
3. The balance includes all SOL tokens, including those delegated for staking
4. The response is immediate as it reads from the current state

## Best Practices

1. Use appropriate commitment level based on your needs:
   * `processed` for UI updates
   * `confirmed` for most operations
   * `finalized` for critical operations
2. Convert lamports to SOL by dividing by 1e9 when displaying to users
3. Consider using `getAccountInfo` if you need more account details

## Common Errors

| Code   | Message                                  | Solution                                      |
| ------ | ---------------------------------------- | --------------------------------------------- |
| -32602 | Invalid param: WrongSize                 | Verify the public key is valid                |
| -32602 | Invalid param: not base58 encoded string | Ensure the public key is base58 encoded       |
| -32007 | Account not found                        | The account doesn't exist (balance will be 0) |
