Inspect Account Balances

This guide helps obtaining and inspecting token balances across different chains

Monitoring your cryptocurrency and DeFi account balances is crucial for maintaining security and managing risk in the Web3 space. Regular balance checks help you:

  • Detect unauthorized transactions or potential exploits targeting smart contracts where you have funds (read about smart contract attacks)
  • Track active token approvals and revoke them if suspicious activity is detected (learn about managing approvals)
  • Make informed decisions about your DeFi positions and portfolio management
  • Maintain real-time awareness of your asset distribution across different protocols

This guide explains how to retrieve ERC-20 token balances for one or multiple addresses. For detailed API specifications, refer to the API documentation.


Getting Balances via cURL

To retrieve account balances, use the following cURL command:

curl --header "X-API-KEY: $YOUR_API_KEY" --request GET "https://svc.blockdaemon.com/defi/v1/balances?chainIDs=eip155:1&accountAddress=0xf271AAFC62634e6Dc9A276ac0f6145C4fDbE2Ced" | jq

Required parameters

  • chainIDs: List of CAIP-2 chain identifiers (e.g., eip155:1,eip155:10)
  • accountAddress: List of account addresses to query balances for

The response includes token balances with their USD values:

{
  "account": "0xf271AAFC62634e6Dc9A276ac0f6145C4fDbE2Ced",
  "balances": [
    {
      "chainID": "eip155:1",
      "tokenBalances": [
        {
          "amount": "542985680920224316",
          "amountUSD": 1639.2086,
          "token": {
            "address": "0x0000000000000000000000000000000000000000",
            "chainID": "eip155:1",
            "decimals": 18,
            "extensions": {
              "homepage": "https://ethereum.org/",
              "verified": true
            },
            "logoURI": "https://defi-images-blockdaemon-research-development-int-aa593eebdaa2fd.gitlab.io/tokens/1-0x0000000000000000000000000000000000000000.webp",
            "name": "Ether",
            "priceUSD": 3018.88,
            "symbol": "ETH",
            "tags": [
              "native",
              "stargateV2"
            ]
          }
        },
        [...]

Getting Balances Programmatically

Our DeFi Examples repo contains example code for using the /balances endpoint programmatically:

const api = new BalancesApi(apiConfig);

const getBalancesRequest: GetBalancesRequest = {
	chainID: "eip155:1",
	accountAddress: process.env.SENDER_ADDRESS
};

try {
	const balances = await api.getBalances(getBalancesRequest);
	log.info("Got balances:", JSON.stringify(balances, null, 2));
	return balances;
} catch (error) {
	log.error("Failed to get balances:", error);
	throw error;
}

To run the balances script, use:

npm exec ts-node src/main/scripts/get-balances.ts

👋 Need Help?

Contact us through email or our support page for any issues, bugs, or assistance you may need.