籌資狀態
// Import Ethers.js
const { ethers } = require("ethers");
// Replace with your Ethereum provider (e.g., Infura, Alchemy, or a local node)
const provider = new ethers.JsonRpcProvider("https://eth-mainnet.g.alchemy.com/v2/your-api-key");
// Replace with the wallet address you want to check
const walletAddress = "0xYourWalletAddressHere";
async function checkBalance() {
try {
// Get the balance in wei
const balanceWei = await provider.getBalance(walletAddress);
// Convert to ETH
const balanceEth = ethers.formatEther(balanceWei);
console.log(`Wallet Address: ${walletAddress}`);
console.log(`Balance: ${balanceEth} ETH`);
} catch (error) {
console.error("Error fetching balance:", error);
}
}
checkBalance();