Created
February 27, 2019 23:42
-
-
Save CHAOWEICHIU/97e964ebe10cc0a5ddcc59f7136978f2 to your computer and use it in GitHub Desktop.
use private to get public key and wallet 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
/* | |
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