Skip to content

Instantly share code, notes, and snippets.

@Stuyk
Created March 15, 2024 03:33
Show Gist options
  • Save Stuyk/2f63ec0b4df30191b3149805ec9b983f to your computer and use it in GitHub Desktop.
Save Stuyk/2f63ec0b4df30191b3149805ec9b983f to your computer and use it in GitHub Desktop.
Ethereum Address & Balance Checker
// This is incredibly stupid and you will never hit an address with a balance.
// Anyway, enjoy.
const bip39 = require("bip39");
const { hdkey } = require("@ethereumjs/wallet");
const { Web3 } = require("web3");
const web3 = new Web3("RPC_ENDPOINT_GOES_HERE");
const generateMnemonic = () => {
return bip39.generateMnemonic();
};
const deriveAddressAndBalance = async (mnemonic) => {
const seed = await bip39.mnemonicToSeed(mnemonic);
const hdWallet = hdkey.EthereumHDKey.fromMasterSeed(seed);
const derivedPath = "m/44'/60'/0'/0/0";
const childNode = hdWallet.derivePath(derivedPath);
const address = childNode.getWallet().getChecksumAddressString();
const balance = await web3.eth.getBalance(address);
return { address, balance };
};
const generateAndCheck = async () => {
try {
const mnemonic = generateMnemonic();
const { address, balance } = await deriveAddressAndBalance(mnemonic);
if (balance != 0) {
console.log(`${mneumonic} | Balance: ${balance}`);
} else {
console.log(`${address} | Balance: ${balance}`);
}
} catch (error) {
console.error("Error:", error);
}
generateAndCheck();
};
for (let i = 0; i < 5; i++) {
generateAndCheck();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment