Get Balance with Carbiun

This example demonstrates how to fetch a wallet’s current SOL balance directly through Carbium RPC using Python.

RPC Check Wallet Balance

This example demonstrates how to fetch a wallet’s current SOL balance directly through Carbium RPC using Python. It’s a quick and reliable way to verify account funds before sending transactions, running arbitrage logic, or managing automated trading strategies.

What it does

  • Connects to Carbium’s high-speed RPC endpoint (https://rpc.carbium.io)
  • Sends a standard getBalance JSON-RPC request
  • Returns the account’s balance in lamports, which are converted to SOL (1 SOL = 1 000 000 000 lamports)

Why it matters

Accurate balance checks are essential when:

  • Executing swaps or limit orders
  • Funding fee accounts for automated bots
  • Monitoring portfolio exposure or liquidity

Example Snippet

# Requires: pip install solana solders

from solana.rpc.api import Client
from solders.transaction import VersionedTransaction

# Connect to Carbium RPC using your API key
# Get your Free API key and 5M calls a month from https://rpc.carbium.io
client = Client("https://rpc-service.carbium.io/?apiKey=************")

# For demo purposes: create an empty transaction (no instructions)
# This is a "dry-run" test — no real tokens move.
empty_tx = VersionedTransaction.unchecked_default()

# Simulate the transaction
simulation = client.simulate_transaction(empty_tx)

# Print full RPC response
print(simulation)

Example output

Wallet balance: 5.431298372 SOL

Notes

  • For production bots, authenticate with your Carbium API key for higher throughput.
  • The same pattern can be used for token accounts by switching to the getTokenAccountsByOwner method.
  • Always handle failed RPC responses (e.g. rate-limits or timeout retries).