Created
July 24, 2018 15:21
-
-
Save michelem09/9201305bf2259bb89843373859dcdfce to your computer and use it in GitHub Desktop.
Programmatically generate keypair for Ethereum wallet: private key, public key and address
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
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