Is there any way to check the balance of a Solana wallet using Python?
I tried using Solscan, but I don't understand how it works and I can't find information about it on the internet.
Is there any way to check the balance of a Solana wallet using Python?
I tried using Solscan, but I don't understand how it works and I can't find information about it on the internet.
You could use solana-py
. If you haven't already, install it through pip install solana
. Then you can run the following Python code to check the balance of your wallet, replacing YOUR_WALLET_ADDRESS
with your actual wallet address.
from solana.rpc.api import Client
from solana.publickey import PublicKey
client = Client("https://api.mainnet-beta.solana")
public_key = PublicKey(wallet_address)
response = client.get_balance(public_key)
balance_lamports = response.value
balance_sol = balance_lamports / 1e9
print(f"Wallet balance: {balance_lamports} lamports ({balance_sol} SOL)")
If you using Binance :
#pip install python-binance
from binance.client import Client
api_key = "API"
secret_key = "SECRET"
#Staring Client
client = Client(api_key, secret_key)
#getting user balance
ac_info = client.get_account()
for balance in ac_info["balances"]
if balance["asset"] == "SOL" # Or BTC etc.
sol_balance = balance.["free"]
print(f"[SOL] Balance : {sol_balance}")
If there is an active sell order, your balance will appear lower.
Second, using requests:
import requests
url = "https://api.solscan.io/account/tokens"
# Your wallet address (Solana public key)
wallet_address = "YOUR_WALLET_ADDRESS"
# Make a request to Solscan's API
response = requests.get(f"{url}?address={wallet_address}")
# Check if the request was successful
if response.status_code == 200:
data = response.json()
# Extract balance information (SOL is typically under 'sol_balance')
sol_balance = data.get('data', {}).get('sol_balance', None)
if sol_balance is not None:
print(f"Wallet Balance: {sol_balance} SOL")
else:
print("Error: Could not find SOL balance.")
else:
print(f"Failed to fetch data: {response.status_code}")