DeveloperBreeze

Transaction Development Tutorials, Guides & Insights

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

Etherscan vs Infura: Choosing the Right API for Your Blockchain Application

Tutorial October 24, 2024

You should use Etherscan when you need to read data from the Ethereum blockchain, such as querying transaction details, wallet balances, or token transfers. Etherscan is a powerful tool for building blockchain explorers or applications that focus on data analytics.

const axios = require('axios');

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

// Replace 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 {
    const response = await axios.get(url);
    const balanceInWei = response.data.result;

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

getWalletBalance();

Sending Transactions and Interacting with Smart Contracts Using Infura and Ethers.js

Tutorial October 24, 2024

If you don't have an Infura account yet, follow these steps:

You’ll use Ethers.js to interact with Ethereum smart contracts and send transactions. Run the following command in your project folder to install it: