Last active
August 10, 2023 19:26
-
-
Save MayowaObisesan/46c2ee92b406037d716f82c3345e93be to your computer and use it in GitHub Desktop.
This script queries your ethereum account balance, transaction count and blockNumber on the ethereum mainnet, sepolia testnet and goerli testnet
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
// Mayowa Obisesan | |
// A script that queries an ethereum account balance, transaction count and blockNumber on ethereum's mainnet, | |
// sepolia and goerli testnet | |
import { ethers } from 'ethers'; | |
const address: string = "0x298AAA9A0822eB8117F9ea24D28c897E83415440"; | |
const accountDetails = async (networkType: string) => { | |
const provider = ethers.getDefaultProvider(networkType); | |
const balance = await provider.getBalance(address); | |
const transactionCount = await provider.getTransactionCount(address); | |
const blockNumber = await provider.getBlockNumber(); | |
console.log(`Details of ${address} on ${networkType}`); | |
console.log("Balance: ", ethers.formatEther(balance), "ethers"); | |
console.log("Transaction Count: ", transactionCount); | |
console.log("Block Number: ", blockNumber); | |
console.log("\n"); | |
return { balance, transactionCount, blockNumber }; | |
} | |
const getAccountNetworkDetails = () => { | |
accountDetails("mainnet"); | |
accountDetails("sepolia"); | |
accountDetails("goerli"); | |
} | |
getAccountNetworkDetails(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment