If you are using Node.js, you can use the package called “ethereumjs-wallet” to generate Ethereum private keys and addresses. This is an official package provided and maintained by the Ethereum JavaScript community.
To generate Ethereum addresses, follow these steps:
Step 1: Create Node project
To create a new Node project, create a new folder and initialize the project using the following command.
Step 2: Install Node dependency
Install the dependency using the following command.
Step 3: Generate Addresses
Here is a code to generate 1000 Ethereum Addresses.
for(let index=0; index < 1000; index++) {
let addressData = ethWallet.generate();
console.log(`Private key = , ${addressData.getPrivateKeyString()}`);
console.log(`Address = , ${addressData.getAddressString()}`);
}
It’s as simple as this.
However, this is not a production approach. You don’t wanna generate a private key on a random basis. If you want to generate addresses from the raw private key you can use this method.
console.log(`Private key = , ${addressData.getPrivateKeyString()}`);
console.log(`Address = , ${addressData.getAddressString()}`);
If you want to generate using the extended private key or xprv which is the most used approach, you can use this code:
console.log(`Private key = , ${addressData.getPrivateKeyString()}`);
console.log(`Address = , ${addressData.getAddressString()}`);
Check out the complete documentation for more detailed information.