A reference implementation for fetching and formatting real-time wallet balances using the Moralis Get Wallet Token Balances API. It demonstrates how to fetch all token balances for a specific wallet address, including current USD prices, in a single API call.
- Fetches balances and prices simultaneously (single endpoint).
- Includes spam and unverified contract filtering.
- Supports multiple chains (Base, Ethereum, Arbitrum, ...) by changing the chain parameter.
- Formats crypto balances and USD values for better readability.
git clone https://github.com/bernie-developer/moralis-token-balances-api.git
npm install
-
Get your API Key: Sign up for the free tier at admin.moralis.com to generate your key.
-
Set your API Key: Choose one of the following methods:
-
Option A (Direct): Replace
YOUR_API_KEYdirectly in the code. -
Option B (Secure): Set a
MORALIS_KEYenvironment variable. The script prioritizes this method.
- Set Wallet Address: Update the address variable with the EVM wallet you wish to query.
const apiKey = "YOUR_API_KEY";
const address = "0x...";
Run the script from your terminal to see the balances in your console:
node index.js
Terminal Output:
This project uses the Moralis Wallet API (v2.2). By using the balance_formatted field, we avoid manual decimal conversions for various token standards (ERC20). The exclude_spam and exclude_unverified_contracts parameters are enabled to ensure data quality.
For more information, see the official Moralis documentation.