DeveloperBreeze

Blockchain Development Programming Tutorials, Guides & Best Practices

Explore 30+ expertly crafted blockchain development tutorials, components, and code examples. Stay productive and build faster with proven implementation strategies and design patterns from DeveloperBreeze.

How to Query ERC-20 Token Balances and Transactions Using Ethers.js and Etherscan API

Tutorial October 24, 2024

In this tutorial, you learned how to use Ethers.js to query ERC-20 token balances and how to leverage the Etherscan API to retrieve token transaction histories. These are essential techniques for building decentralized applications, wallets, or blockchain explorers that interact with ERC-20 tokens on the Ethereum network.

You now have the tools to query token balances and transaction histories programmatically, enabling you to create powerful blockchain-based applications.

Understanding and Using the Etherscan API to Query Blockchain Data

Tutorial October 24, 2024

Let’s create a Node.js script to query the balance of an Ethereum wallet using the Etherscan API.

const axios = require('axios');

// Replace this with your actual Etherscan API key
const apiKey = 'YOUR_ETHERSCAN_API_KEY';

// Replace this with the Ethereum address you want to query
const address = '0xYourEthereumAddress';

// Etherscan API URL to fetch wallet balance
const url = `https://api.etherscan.io/api?module=account&action=balance&address=${address}&tag=latest&apikey=${apiKey}`;

async function getWalletBalance() {
  try {
    // Make the API request to Etherscan
    const response = await axios.get(url);
    const balanceInWei = response.data.result;

    // Convert balance from Wei to Ether
    const balanceInEther = balanceInWei / 1e18;
    console.log(`Wallet Address: ${address}`);
    console.log(`Wallet Balance: ${balanceInEther} ETH`);
  } catch (error) {
    console.error('Error fetching balance:', error);
  }
}

// Call the function to get the balance
getWalletBalance();

Tracking Solana Address for New Trades and Amounts

Tutorial August 09, 2024
javascript nodejs

   npm init -y
   npm install @solana/web3.js