Skip to content

Instantly share code, notes, and snippets.

@CHAOWEICHIU
Created February 27, 2019 23:42
Show Gist options
  • Save CHAOWEICHIU/97e964ebe10cc0a5ddcc59f7136978f2 to your computer and use it in GitHub Desktop.
Save CHAOWEICHIU/97e964ebe10cc0a5ddcc59f7136978f2 to your computer and use it in GitHub Desktop.
use private to get public key and wallet address
/*
Requirement
--------------
node: v8.10.0
npm: v5.6.0
--------------
npm installation
---------------------------------------------
npm install ethereumjs-wallet ethereumjs-util
---------------------------------------------
*/
const Wallet = require('ethereumjs-wallet')
const Util = require('ethereumjs-util')
// Get a wallet instance from a private key
const privateKeyBuffer = Util.toBuffer('0x61ce8b95ca5fd6f55cd97ac60817777bdf64f1670e903758ce53efc32c3dffeb')
const wallet = Wallet.fromPrivateKey(privateKeyBuffer)
// Get a public key
const publicKey = wallet.getPublicKeyString()
// Get a wallet address
const walletAddress = wallet.getChecksumAddressString()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment