DEV Community

Zaenal Arifin
Zaenal Arifin

Posted on

How to Easily Check Multi-Chain Crypto Wallet Balances with FastAPI API

Crypto developers often face challenges when checking wallet balances or transaction statuses across multiple blockchains. Doing it manually can be tedious, especially if you need to support Solana, Ethereum, BSC, or Polygon at the same time.

Fortunately, the Crypto API Service allows developers to directly query blockchain data via ready-to-use API endpoints, without running nodes themselves. In this article, we’ll create a Python async mini project to check wallet balances using this API.


1️⃣ Setup

  • Python 3.11+
  • Install dependencies:
pip install httpx asyncio
Enter fullscreen mode Exit fullscreen mode
  • RapidAPI key (sign up on RapidAPI and subscribe to the Crypto API Service)

2️⃣ Example Python Project

Create a file called check_balance.py:

# check_balance.py
import asyncio
import httpx
import logging

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

API_URL = "https://api.aigoretech.cloud/api/v1/crypto/balance"
API_KEY = "YOUR_RAPIDAPI_KEY"  # replace with your RapidAPI key

async def get_balance(chain: str, wallet: str):
    """Async function to fetch wallet balance on a specific chain"""
    async with httpx.AsyncClient() as client:
        try:
            resp = await client.get(
                API_URL,
                params={"chain": chain, "wallet": wallet},
                headers={"X-RapidAPI-Key": API_KEY}
            )
            resp.raise_for_status()
            data = resp.json()
            logger.info(f"Balance data: {data}")
            return data
        except httpx.HTTPError as e:
            logger.error(f"Failed to fetch data: {e}")
            return None

async def main():
    chain = "sol"
    wallet = "BnwKsYcEYMCZBTdgTQ8NE3QT79Yj"
    balance_data = await get_balance(chain, wallet)
    if balance_data:
        print(f"Wallet: {balance_data['wallet']}")
        print(f"Chain: {balance_data['chain']}")
        print(f"Balance: {balance_data['balance']}")

if __name__ == "__main__":
    asyncio.run(main())
Enter fullscreen mode Exit fullscreen mode

3️⃣ Output

When running the script with a real wallet, the JSON output looks like:

{
  "status": "ok",
  "chain": "sol",
  "wallet": "BnwKsYcEYMCZBTdgTQ8NE3QT79Yj",
  "balance": 12.345
}
Enter fullscreen mode Exit fullscreen mode

Console output:

Wallet: BnwKsYcEYMCZBTdgTQ8NE3QT79Yj
Chain: sol
Balance: 12.345
Enter fullscreen mode Exit fullscreen mode

4️⃣ How to Run

  1. Save the script as check_balance.py
  2. Replace YOUR_RAPIDAPI_KEY with your RapidAPI key
  3. Run:
python check_balance.py
Enter fullscreen mode Exit fullscreen mode
  1. See the wallet balance printed on the console

5️⃣ Closing

With just a few lines of code, you can check multi-chain wallet balances without running your own blockchain nodes. This is very useful for developers building crypto dashboards, trading bots, or monitoring tools.

If you want to explore more endpoints, try the Crypto API Service on RapidAPI and integrate it into your own projects.

Top comments (0)