Skip to content

Instantly share code, notes, and snippets.

@otoloye
Created August 5, 2023 16:11
Show Gist options
  • Save otoloye/8846ae038efa97c985243a6d4a7dfd1a to your computer and use it in GitHub Desktop.
Save otoloye/8846ae038efa97c985243a6d4a7dfd1a to your computer and use it in GitHub Desktop.
// Import the ethers library
const ethers = require('ethers');
// Connect to the Ethereum mainnet
let provider = new ethers.providers.JsonRpcProvider('https://mainnet.infura.io/v3/INFURA_PROJECT_ID');
// Define the addresses to look up
let addresses = [
'0x57f1887a8BF19b14fC0dF6Fd9B2acc9Af147eA85',
'0xf4bfaf916a68b0fC859D63a319034C0f72A88a5C',
'0x3b138FC7eC06B2A44565994CfDe5134A75915995'
];
addresses.forEach((address) => {
// Fetch the balance of the address
provider.getBalance(address).then((balance) => {
let etherString = ethers.utils.formatEther(balance);
console.log('Balance of', address, ':', etherString);
});
// Fetch the transaction count of the address
provider.getTransactionCount(address).then((txCount) => {
console.log('Transaction Count of', address, ':', txCount);
});
// Determine if the address is a contract
provider.getCode(address).then((code) => {
if(code === '0x') {
console.log(address, 'is an Externally Owned Account (EOA)');
} else {
console.log(address, 'is a Contract Account');
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment