Created
April 1, 2023 03:43
-
-
Save ZacharyCouchman/a2dd1c11ff4f0319a32c0d0cfc0e9727 to your computer and use it in GitHub Desktop.
Getting the ETH balance of a wallet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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