Skip to content

bernie-developer/moralis-token-balances-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Moralis Token Balances API Demo

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.

Features

  • 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.

Setup

1. Clone the repository:

git clone https://github.com/bernie-developer/moralis-token-balances-api.git

2. Install dependencies:

npm install

3. Configuration: Open index.js to configure the script:

  1. Get your API Key: Sign up for the free tier at admin.moralis.com to generate your key.

  2. Set your API Key: Choose one of the following methods:

  • Option A (Direct): Replace YOUR_API_KEY directly in the code.

  • Option B (Secure): Set a MORALIS_KEY environment variable. The script prioritizes this method.

  1. Set Wallet Address: Update the address variable with the EVM wallet you wish to query.
const apiKey = "YOUR_API_KEY";
const address = "0x...";

Usage

Run the script from your terminal to see the balances in your console:

node index.js

Terminal Output:

output

Technical Details

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.

API Documentation

For more information, see the official Moralis documentation.

About this Project

Originally a second-stage assessment task requiring both this code and a tutorial video. Interestingly, while the requested video stayed at 0 views, developers found the code useful once I made it public. I’ve decided to keep it online as a simple, working example.

About

Fetch and display wallet token balances using Moralis API

Resources

License

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors