Skip to content

Instantly share code, notes, and snippets.

@michelem09
Created July 24, 2018 15:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save michelem09/9201305bf2259bb89843373859dcdfce to your computer and use it in GitHub Desktop.
Save michelem09/9201305bf2259bb89843373859dcdfce to your computer and use it in GitHub Desktop.
Programmatically generate keypair for Ethereum wallet: private key, public key and address
var keythereum = require('keythereum');
var Wallet = require('ethereumjs-wallet');
// Generate private key
var dk = keythereum.create();
var keyObject = keythereum.dump('password', dk.privateKey, dk.salt, dk.iv);
var privateKeyString = dk.privateKey.toString('hex');
console.log('Private key', privateKeyString);
// Get public key
var wallet = Wallet.fromPrivateKey(dk.privateKey);
var publicKey = wallet.getPublicKey();
console.log('Public key', publicKey.toString('hex'));
// Get wallet address
var address = wallet.getAddressString();
console.log('Address', address);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment