Skip to main content

getBalance

Returns the lamport balance of the account of provided Pubkey

Common use cases
Wallet balance displayDisplay user's SOL holdings in wallets and dashboards. Convert lamports to SOL using division by 1_000_000_000. Use confirmed commitment for responsive UX while awaiting finality.
Pre-transaction validationVerify account has sufficient balance before submitting transactions. Check balance exceeds transaction cost plus rent exemption minimum to prevent failures.
Account existence checkDetermine if account exists on-chain by checking for non-zero balance. Non-existent accounts return 0 lamports. Use with getAccountInfo for comprehensive validation.
Balance change monitoringPoll balance at intervals to detect incoming transfers or transaction settlements. Use commitment parameter to balance responsiveness vs. finality guarantees based on use case.

Parameters

pubkey (string, required)

Pubkey of account to query, as base-58 encoded string.

config (object, optional)

Configuration object.

Fields:

  • commitment (string): The commitment describes how finalized a block is at that point in time. See Configuring State Commitment.
  • minContextSlot (number): The minimum slot that the request can be evaluated at.

Request

curl https://solana-mainnet.api.syndica.io/api-key/YOUR_API_KEY \
-X POST \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "getBalance",
"params": [
"83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcri",
{
"commitment": "finalized"
}
]
}'
Network Selection

Replace mainnet with devnet in the URL to query devnet instead.

Response

{
"jsonrpc": "2.0",
"result": {
"context": { "slot": 1 },
"value": 0
},
"id": 1
}

Response Fields

Return value: u64

RpcResponse JSON object with value field set to the balance.

FAQ and Troubleshooting

Why is my balance 0 immediately after a transaction?

Balance updates depend on commitment level. Use processed for fastest updates (may revert on fork), confirmed for medium latency (unlikely to revert), or finalized for guaranteed finality (2-3 second delay). The transaction may also still be pending.

What causes "fetch failed" errors when calling getBalance?

Common in serverless environments (AWS Lambda) due to network timeouts or connection pooling issues. Implement retry logic with exponential backoff and ensure RPC endpoint is accessible from your runtime environment.

How do I check balances for multiple accounts efficiently?

Use getMultipleAccounts for bulk queries instead of multiple getBalance calls. This reduces RPC requests and improves performance when checking 5+ accounts simultaneously.

What's the difference between lamports and SOL?

Lamports are the smallest unit (1 SOL = 1,000,000,000 lamports). getBalance always returns lamports. Convert to SOL by dividing by LAMPORTS_PER_SOL constant for display purposes.

getAccountInfo
Returns full account data including balance, owner, and data. Use when you need more than just balance, such as validating account type or reading stored data.

getMultipleAccounts
Fetches multiple accounts in a single RPC call. More efficient than repeated getBalance calls when checking 5+ accounts, reduces network overhead and API rate limit consumption.

getTokenAccountBalance
Retrieves SPL token balance for token accounts. Use for fungible token balances; getBalance only returns native SOL lamports.

getMinimumBalanceForRentExemption
Calculates minimum lamports needed for rent exemption. Use before account creation or when validating sufficient balance for program accounts.

External Resources