Understanding the ERC-20 token holdings of a blockchain address is essential for developers, auditors, researchers, and organizations monitoring on-chain activity. While wallet applications display token balances for their users, accessing this data for any arbitrary Ethereum address requires a more technical approach—specifically, leveraging blockchain APIs.
This guide walks you through how to retrieve all ERC-20 tokens owned by a given address using three leading Web3 infrastructure platforms: Chainbase, Alchemy, and Moralis. Each service offers robust APIs that allow seamless access to on-chain data without direct wallet access.
We’ll provide step-by-step instructions in JavaScript, ensuring you can implement these solutions efficiently in your development workflow.
Core Keywords
- ERC-20 token balance
- blockchain API
- Ethereum address lookup
- Web3 development
- on-chain data query
- fetch token holdings
- wallet token scanner
These keywords reflect the primary search intent behind queries related to retrieving token data from Ethereum addresses. They are naturally integrated throughout this article to enhance SEO performance while maintaining readability.
Using Chainbase to Retrieve ERC-20 Token Balances
Chainbase provides a powerful Web3 interaction layer that simplifies blockchain data access. Its API allows developers to query token balances across multiple networks with minimal setup.
Step 1: Create a Free Account and Obtain an API Key
Begin by registering a free account at Chainbase. Once logged in, navigate to the dashboard and create a new project. From there, generate your unique API key—this will authenticate your requests when querying blockchain data.
👉 Discover how easy it is to start querying blockchain data with powerful tools.
Step 2: Write a Script Using the Chainbase API
To retrieve ERC-20 token balances, use JavaScript with the Axios library for HTTP requests. First, install Axios:
npm install axios --saveThen, write a script that calls the getAccountTokens endpoint:
const axios = require('axios');
const API_KEY = 'your_chainbase_api_key';
const ADDRESS = '0xd8da6bf26964af9d7eed9e03e53415d37aa96045'; // Vitalik's address
const CHAIN_ID = '1'; // Ethereum Mainnet
async function fetchTokens() {
try {
const response = await axios.get(
`https://api.chainbase.com/api/v1/account/tokens?chain_id=${CHAIN_ID}&address=${ADDRESS}`,
{
headers: { 'X-API-Key': API_KEY }
}
);
console.log(response.data);
} catch (error) {
console.error('Error fetching tokens:', error.message);
}
}
fetchTokens();This script queries Chainbase for the first few ERC-20 token balances held by the specified Ethereum address.
Step 3: Display Token Information
Run the script using:
node script.jsThe output includes token contract addresses, balances (in smallest units), and metadata such as name and symbol where available. You can extend the script to filter or format results as needed.
Using Alchemy to Query ERC-20 Holdings
Alchemy is one of the most trusted platforms for Web3 developers, offering high-performance APIs for reading and writing blockchain data.
Step 1: Install Node.js and NPM
Ensure Node.js and NPM are installed on your system. These tools are essential for running JavaScript-based scripts locally.
Step 2: Sign Up and Create an App on Alchemy
Visit Alchemy’s website and sign up for a free account. After logging in, go to the dashboard and create a new app. Select Ethereum as the chain and Mainnet as the network. Copy the HTTP URL provided—it contains your API key.
Example URL:
https://eth-mainnet.g.alchemy.com/v2/your-api-keyStep 3: Initialize a Node Project
Create a new directory and initialize it:
mkdir eth-balance && cd eth-balance
npm init -y
npm install @alch/alchemy-web3Step 4: Fetch Token Balances with Alchemy SDK
Use the following code in main.js:
const { Alchemy, Network } = require('alchemy-web3');
const alchemy = Alchemy('your-api-key', Network.ETH_MAINNET);
async function getTokenBalances() {
const address = '0xd8da6bf26964af9d7eed9e03e53415d37aa96045';
const balances = await alchemy.core.getTokenBalances(address);
for (let token of balances.tokenBalances) {
if (token.tokenBalance !== '0x0') {
const metadata = await alchemy.core.getTokenMetadata(token.contractAddress);
console.log({
name: metadata.name,
symbol: metadata.symbol,
balance: parseInt(token.tokenBalance, 16) / Math.pow(10, metadata.decimals)
});
}
}
}
getTokenBalances();This script retrieves non-zero token balances and converts them into human-readable form using token metadata.
👉 Access real-time blockchain data with advanced developer tools today.
Using Moralis to Fetch All ERC-20 Tokens
Moralis streamlines Web3 development with enterprise-grade APIs designed for scalability and ease of use.
Step 1: Set Up Moralis Environment
Install Node.js (v14 or higher) and NPM. Then, create a free Moralis account and log in to the dashboard. Navigate to Settings > Secrets and copy your Web3 API Key.
Step 2: Query Token Balances via Moralis API
Moralis provides the getWalletTokenBalances endpoint. Here's how to use it:
const Moralis = require('moralis').default;
async function getTokens() {
await Moralis.start({
apiKey: 'your-moralis-api-key'
});
const response = await Moralis.EvmApi.wallet.getWalletTokenBalances({
address: '0xd8da6bf26964af9d7eed9e03e53415d37aa96045',
chain: '1' // Ethereum Mainnet
});
console.log(response.raw);
}
getTokens();Install Moralis SDK first:
npm install moralisStep 3: Run the Script
Execute with:
node main.jsThe JSON response includes detailed token information: contract address, name, symbol, decimals, logo URL (if available), and balance in raw format. You can further process this data for display or analysis.
Frequently Asked Questions (FAQ)
Q: Can I get ERC-20 token balances without an API?
A: Yes, but it's inefficient. You'd need to manually query each token contract using tools like Etherscan or smart contract calls. APIs automate this across thousands of tokens.
Q: Are these methods safe for production use?
A: Absolutely. Chainbase, Alchemy, and Moralis are widely used in production dApps and support rate limiting, authentication, and scalable infrastructure.
Q: Do I need to pay to use these APIs?
A: All three platforms offer generous free tiers suitable for development and moderate usage. Paid plans unlock higher request limits and priority support.
Q: Can I retrieve NFTs using similar methods?
A: Yes—each platform also supports ERC-721 and ERC-1155 NFT balance queries through dedicated endpoints.
Q: Is the balance returned in readable format?
A: Not always. Balances are typically returned in wei or the token’s smallest unit. Use the decimals field to convert them into user-friendly numbers.
Q: What if an address holds hundreds of tokens?
A: Most APIs paginate results or limit responses. Adjust parameters like limit or page to retrieve full datasets incrementally.
Final Thoughts
Retrieving all ERC-20 tokens owned by an Ethereum address is straightforward with modern Web3 APIs. Whether you choose Chainbase, Alchemy, or Moralis, each platform offers reliable, well-documented tools that integrate seamlessly into development environments.
By automating token balance checks, developers can build powerful analytics dashboards, compliance tools, portfolio trackers, and security scanners—all without direct access to private keys or wallets.
👉 Unlock the full potential of blockchain data with developer-first tools.
With just a few lines of code, you can gain deep insights into on-chain activity—making Web3 development faster, smarter, and more efficient than ever before.