Skip to content

Instantly share code, notes, and snippets.

@VictorNS69
Last active August 20, 2021 07:28
Show Gist options
  • Save VictorNS69/b5489a630ceff6e5877cc27d7b217ef4 to your computer and use it in GitHub Desktop.
Save VictorNS69/b5489a630ceff6e5877cc27d7b217ef4 to your computer and use it in GitHub Desktop.
Creates a new Ethereum Keystore
// Usage: node create_eth_keystore.js
// Node v10+
// Dependencies
// npm i ethereumjs-wallet@0.6.3
const Wallet = require('ethereumjs-wallet')
const accountPassword = "" // Put here the password you want for your keystore
const key = Wallet.generate(accountPassword)
const privateKey = key._privKey
const wallet = Wallet.fromPrivateKey(privateKey)
const keystoreData = wallet.toV3String(accountPassword)
const address = "0x" + JSON.parse(keystoreData).address
console.log("Account Address:", address)
console.log("Public key:", wallet.getPublicKeyString())
console.log("Private key:", wallet.getPrivateKeyString())
console.log("Keystore:\n", JSON.stringify(JSON.parse(keystoreData), null, 2))
@onmax
Copy link

onmax commented Sep 30, 2020

To get the public and private key from wallet as a String. You can also get them as a Byte[] removing String from the function

console.log("Public key:", wallet.getPublicKeyString())
console.log("Private key:", wallet.getPrivateKeyString())

@VictorNS69
Copy link
Author

To get the public and private key from wallet as a String. You can also get them as a Byte[] removing String from the function

console.log("Public key:", wallet.getPublicKeyString())
console.log("Private key:", wallet.getPrivateKeyString())

Thanks! I have edited the code 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment