Skip to content

Instantly share code, notes, and snippets.

@ZacharyCouchman
Created April 1, 2023 03:43
Show Gist options
  • Save ZacharyCouchman/a2dd1c11ff4f0319a32c0d0cfc0e9727 to your computer and use it in GitHub Desktop.
Save ZacharyCouchman/a2dd1c11ff4f0319a32c0d0cfc0e9727 to your computer and use it in GitHub Desktop.
Getting the ETH balance of a wallet
import { ethers } from "ethers"
import { formatEther } from "ethers/lib/utils.js";
const walletAddress = ""; // add the wallet address you want to check the balance of
const rpcUrl = "https://eth-mainnet.g.alchemy.com/v2/demo";
async function getWalletBalance(){
const provider = new ethers.providers.JsonRpcProvider(rpcUrl);
const balance = await provider.getBalance(walletAddress);
console.log(`ETH balance of ${walletAddress} is ${formatEther(balance)}`)
}
getWalletBalance();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment