Introduction
In this tutorial, you’ll learn how to retrieve all ERC20 token balances for a wallet address using the Moralis API. This is essential for building portfolio trackers, wallet dashboards, or any application that needs to display a user’s token holdings. We’ll use the following Moralis API endpoint:- Get Wallet Token Balances - Fetch all ERC20 tokens held by a wallet
Prerequisites
- Node.js v18+ installed
- A Moralis API key (get one free)
Step 1: Set Up Your Project
Create a new directory for your project and initialize it:Step 2: Create the Script
Create a file calledindex.js and add the following code:
YOUR_API_KEY with your actual Moralis API key.
Step 3: Run the Script
Execute the script to fetch the token balances:Example Response
Understanding the Response
| Field | Description |
|---|---|
token_address | The contract address of the ERC20 token |
symbol | The token’s ticker symbol (e.g., USDC) |
name | The full name of the token |
decimals | Number of decimal places the token uses |
balance | Raw token balance (in smallest unit) |
balance_formatted | Human-readable balance with decimals applied |
usd_price | Current USD price of the token |
usd_value | Total USD value of the token balance |
possible_spam | Whether the token is flagged as potential spam |
verified_contract | Whether the token contract is verified |
portfolio_percentage | Percentage this token represents in the wallet |
Next Steps
- Get Token Metadata - Learn how to get detailed token information
- Get Token Price - Fetch current token prices
- API Reference - Full API documentation

