DeveloperBreeze

Etherscan Api Development Tutorials, Guides & Insights

Unlock 3+ expert-curated etherscan api tutorials, real-world code snippets, and modern dev strategies. From fundamentals to advanced topics, boost your etherscan api skills on DeveloperBreeze.

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

Tutorial October 24, 2024

In this step, we will use Ethers.js to query the balance of an ERC-20 token for a specific Ethereum address.

const ethers = require('ethers');

// Replace with your Infura or other Ethereum node provider URL
const provider = new ethers.JsonRpcProvider('https://mainnet.infura.io/v3/YOUR_INFURA_PROJECT_ID');

// Replace with the ERC-20 token contract address (e.g., USDT, DAI)
const contractAddress = '0xTokenContractAddress';

// Replace with the wallet address you want to query
const walletAddress = '0xYourEthereumAddress';

// ERC-20 token ABI (just the balanceOf function)
const abi = [
    'function balanceOf(address owner) view returns (uint256)'
];

// Create a contract instance
const contract = new ethers.Contract(contractAddress, abi, provider);

async function getTokenBalance() {
    try {
        // Query the balance
        const balance = await contract.balanceOf(walletAddress);

        // Convert balance to a human-readable format (tokens usually have 18 decimals)
        const formattedBalance = ethers.utils.formatUnits(balance, 18);

        console.log(`Token Balance: ${formattedBalance}`);
    } catch (error) {
        console.error('Error fetching token balance:', error);
    }
}

// Call the function to get the token balance
getTokenBalance();

Understanding and Using the Etherscan API to Query Blockchain Data

Tutorial October 24, 2024

   https://api.etherscan.io/api?module=account&action=txlist&address=0xYourEthereumAddress&startblock=0&endblock=99999999&sort=asc&apikey=YOUR_API_KEY
   https://api.etherscan.io/api?module=account&action=tokentx&address=0xYourEthereumAddress&startblock=0&endblock=99999999&sort=asc&apikey=YOUR_API_KEY

Tracking Newly Created Tokens on Ethereum

Tutorial August 09, 2024
javascript nodejs

  • Node.js and npm installed on your system.
  • Basic knowledge of JavaScript and Ethereum.
  • An Etherscan API key (you can obtain one by signing up on Etherscan).

Step 1: Set Up Your Project