Ethereum Balance Inquiry: Mastering ETH and Token Balance Checks with Node.js

·

Blockchain technology has revolutionized the way we think about digital ownership, decentralized systems, and financial transactions. For developers, especially those with a background in frontend development, diving into blockchain opens up a world of new tools, concepts, and opportunities. One of the most fundamental and practical skills in Ethereum development is querying balances — both for the native cryptocurrency Ether (ETH) and for ERC-20 tokens. This guide walks you through how to use Node.js and Web3.js to retrieve Ethereum mainnet balances and token details with precision and clarity.

Whether you're building a wallet interface, a decentralized application (dApp), or simply exploring blockchain integration, understanding balance retrieval is essential. Let’s explore how to implement this step by step.


Querying Ethereum (ETH) Balance Using Web3.js

The Ethereum blockchain allows developers to interact with its network using public JSON-RPC APIs. With the help of the Web3.js library, we can easily connect to an Ethereum node and retrieve account information — starting with the ETH balance.

To get started, ensure you have web3.js installed in your Node.js environment:

npm install web3

Next, initialize the Web3 instance and connect to an Ethereum provider (like Infura or a local node):

const Web3 = require('web3');
const web3 = new Web3('https://mainnet.infura.io/v3/YOUR_INFURA_PROJECT_ID');

Now, use the getBalance() method to retrieve the balance of any Ethereum public address:

const address = '0xYourEthereumAddressHere';
web3.eth.getBalance(address).then(balance => {
  console.log('Balance in Wei:', balance);
});

👉 Discover how to securely connect to Ethereum nodes and manage digital assets

Converting Wei to Ether

It's important to note that Ethereum returns balances in wei, the smallest denomination of Ether (1 ETH = 10¹⁸ wei). To make this value human-readable, convert it using fromWei:

web3.eth.getBalance(address).then(balance => {
  const etherBalance = web3.utils.fromWei(balance, 'ether');
  console.log('Balance in ETH:', etherBalance);
});

This conversion is crucial for displaying user-friendly values in dApps or dashboards. Always perform this step before presenting balance data to end users.


Retrieving ERC-20 Token Balances

While ETH is the native currency of the Ethereum network, most blockchain applications involve tokens — typically built using the ERC-20 standard. These tokens represent anything from utility tokens to governance rights or digital collectibles.

To query a token balance, you need two key pieces of information:

Step 1: Initialize the Contract Instance

Using Web3.js, create a contract instance by passing the ABI and contract address:

const contractAddress = '0xTokenContractAddress';
const contractABI = [ /* ABI JSON array */ ];

const contract = new web3.eth.Contract(contractABI, contractAddress);

You can usually find the ABI on block explorers like Etherscan by navigating to the token’s contract page and copying the ABI under the "Contract" tab.

Step 2: Fetch Token Metadata

Once the contract instance is ready, you can call standard ERC-20 methods to retrieve token details:

// Get token name
contract.methods.name().call().then(name => {
  console.log('Token Name:', name);
});

// Get token symbol
contract.methods.symbol().call().then(symbol => {
  console.log('Symbol:', symbol);
});

// Get number of decimals
contract.methods.decimals().call().then(decimals => {
  console.log('Decimals:', decimals);
});

These values are essential for formatting balances correctly and identifying tokens accurately.

Step 3: Query User Token Balance

To get the balance of a specific user (address), use the balanceOf() method:

const userAddress = '0xUserWalletAddress';

contract.methods.balanceOf(userAddress).call().then(balance => {
  console.log('Raw Token Balance:', balance.toString());
});

Just like with ETH, the returned balance is in raw units — based on the token’s decimal precision. For example, if a token uses 6 decimals, a balance of 1,000,000 means 1 full token.

Step 4: Format Balance for Readability

Use fromWei again — but this time specify the actual number of decimals:

contract.methods.decimals().call().then(decimals => {
  const formattedBalance = web3.utils.fromWei(balance.toString(), 'ether'); // or use `10**decimals`
  console.log(`Formatted Balance: ${formattedBalance} ${symbol}`);
});

Alternatively, use dynamic formatting:

const formattedBalance = balance / Math.pow(10, decimals);

This ensures accurate display across different tokens with varying decimal places.

👉 Learn how to manage multi-asset portfolios with advanced blockchain tools


Core Keywords for SEO Optimization

To align with search intent and improve visibility, here are the core keywords naturally integrated throughout this article:

These terms reflect common developer searches and ensure the content ranks well for technical queries related to Ethereum and token management.


Frequently Asked Questions (FAQ)

How do I get the ABI of an ERC-20 token?

You can retrieve the ABI from block explorers like Etherscan. Go to the token’s contract page, navigate to the “Contract” tab, and click “Copy ABI.” Ensure you’re using the verified contract source.

Can I query balances without running my own node?

Yes. You can use third-party services like Infura, Alchemy, or QuickNode to access Ethereum nodes via API keys. These platforms provide reliable access without requiring you to maintain infrastructure.

Why is my balance returned in such a large number?

Ethereum and most tokens use wei or raw units for precision. Always convert using fromWei() or divide by 10^decimals to get the human-readable value.

What is the difference between ETH and ERC-20 token balances?

ETH is the native currency of Ethereum and is queried directly via getBalance(). ERC-20 tokens are smart contracts, so you must interact with their contract address using specific methods like balanceOf().

Is it safe to expose my Infura key in frontend code?

While your Infura key isn’t a private key, it should still be protected. Avoid hardcoding it in client-side code if possible. Use environment variables and consider rate-limiting or firewall rules through your provider.

Can one address hold multiple ERC-20 tokens?

Absolutely. A single Ethereum address can hold any number of ERC-20 tokens simultaneously. Each requires a separate contract instance to query its balance.


Final Thoughts

Querying Ethereum and token balances is a foundational skill in blockchain development. By leveraging Node.js, Web3.js, and public APIs, developers can build powerful tools that interact seamlessly with the Ethereum ecosystem. Whether you're checking ETH balances or retrieving detailed token information — including name, symbol, and decimal precision — the process is both systematic and scalable.

As blockchain continues to evolve, mastering these core interactions will empower developers to create more intuitive, transparent, and user-friendly applications.

👉 Explore next-generation blockchain development tools and resources