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.

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

In this tutorial, you learned how to use Ethers.js with Infura to send Ether, interact with smart contracts, and deploy contracts on the Ethereum blockchain. This setup allows you to interact with the blockchain in real-time without the need to run your own Ethereum node, making it easier to develop decentralized applications (dApps) and other blockchain-based services.

Using Infura for node access and Ethers.js for transaction management and contract interaction gives you a powerful combination to build on Ethereum.

Getting Wallet Balance Using Ethers.js in Node.js

Tutorial October 24, 2024

const ethers = require('ethers');

// Replace this with your Ethereum wallet's private key or mnemonic phrase
const privateKey = 'YOUR_PRIVATE_KEY_OR_MNEMONIC';

// Replace this with your Infura Project ID
const infuraProvider = new ethers.JsonRpcProvider('https://mainnet.infura.io/v3/YOUR_INFURA_PROJECT_ID');

// Create a wallet instance using your private key and connect it to the Infura provider
const wallet = new ethers.Wallet(privateKey, infuraProvider);

// Function to get the balance of the wallet
async function getWalletBalance() {
    // Get the wallet's balance in wei
    const balanceInWei = await wallet.getBalance();

    // Convert the balance from wei to Ether for readability
    const balanceInEther = ethers.utils.formatEther(balanceInWei);

    // Log the results
    console.log(`Wallet Address: ${wallet.address}`);
    console.log(`Wallet Balance: ${balanceInEther} ETH`);
}

// Execute the function
getWalletBalance();

If you don't want to use Infura, you can connect to a public Ethereum node:

Blockchain Development Tools, Libraries, and Frameworks Cheatsheet

Cheatsheet August 23, 2024
solidity

  • Description: The main programming language for writing smart contracts on Ethereum.
  • Key Features:
  • Statically-typed language designed for the Ethereum Virtual Machine (EVM).
  • Supports inheritance, libraries, and user-defined types.
  • Extensive support for complex data types like structs and mappings.
  • Integrated development environment support in Remix, Truffle, and Hardhat.
  • Website: Solidity
  • Description: A peer-to-peer file system for storing and sharing files in a distributed manner.
  • Key Features:
  • Decentralized file storage and sharing.
  • Files are content-addressed using cryptographic hashes.
  • Ideal for storing DApp data, metadata, and files.
  • Easily integrates with Ethereum and other blockchains.
  • Website: IPFS