Cryptocurrency enthusiasts often need to track ERC20 token balances associated with specific wallet addresses. This guide demonstrates how to use Chainbase's getAccountTokens API to efficiently retrieve token holdings programmatically.
Table of Contents
- Introduction
- Prerequisites
- Setting Up a Chainbase Account
- Script Implementation Using Chainbase API
- Interpreting ERC20 Token Balance Data
- Conclusion
- FAQs
1. Introduction
Managing crypto assets requires tools that can automatically fetch ERC20 token balances. Chainbase's API provides a streamlined solution to:
- Retrieve comprehensive token holdings data
- Support multiple blockchain networks
- Return structured JSON responses for easy integration
👉 Explore advanced blockchain APIs
2. Prerequisites
Before implementation, ensure you have:
| Requirement | Description |
|---|---|
| Chainbase Account | Free tier available with API key access |
| Development Environment | VS Code or any JavaScript-capable IDE |
| Wallet Address | Ethereum-compatible address (0x...) |
3. Setting Up a Chainbase Account
- Register at Chainbase
- Navigate to Dashboard → Create Project
- Generate API keys under Project Settings
- Whitelist IP addresses if required
4. Script Implementation Using Chainbase API
Method A: Using Fetch API
const network_id = '1'; // Ethereum Mainnet
const wallet_addr = '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045';
fetch(`https://api.chainbase.online/v1/account/tokens?chain_id=${network_id}&address=${wallet_addr}&limit=5`, {
method: 'GET',
headers: {
'x-api-key': 'YOUR_API_KEY',
'accept': 'application/json'
}
})
.then(response => response.json())
.then(data => console.log(data.data));Method B: Using Axios
const axios = require('axios');
const options = {
url: `https://api.chainbase.online/v1/account/tokens?chain_id=1&address=0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045&limit=5`,
method: 'GET',
headers: {
'x-api-key': 'YOUR_API_KEY',
'accept': 'application/json'
}
};
axios(options)
.then(response => console.log(response.data.data));👉 Need help with API integration?
5. Interpreting ERC20 Token Balance Data
Sample API response:
{
"balance": "0x2386f26fc10000",
"contract_address": "0x954b7997b8bfa9b3d642c477549e284551012f05",
"decimals": 9,
"name": "Eterium",
"symbol": "ETE"
}Key fields explained:
balance: Token amount in hexadecimal formatcontract_address: ERC20 token contract addressdecimals: Token divisibility (18 = standard)- Conversion tip:
hexBalance/(10^decimals)
6. Conclusion
Chainbase's API provides:
- Real-time token balance tracking
- Multi-chain support
- Developer-friendly JSON responses
Ideal for building:
- Portfolio trackers
- Tax reporting tools
- Wallet analytics dashboards
7. FAQs
Q1: What chains does this API support?
A: Ethereum, Polygon, BSC, Arbitrum, and 20+ EVM-compatible networks.
Q2: How do I handle rate limits?
A: Free tier allows 5 requests/second. Consider batch requests for large-scale operations.
Q3: Can I filter by specific tokens?
A: Yes, append &contract_address=TOKEN_ADDRESS to your API request.
Q4: How fresh is the balance data?
A: Updated every 3 blocks (~45 seconds on Ethereum).
Q5: Are there SDKs available?
A: Currently REST API only, but community SDKs exist for Python and Java.