Skip to content

Instantly share code, notes, and snippets.

@AlwaysBCoding
Last active November 2, 2018 19:13
Show Gist options
  • Save AlwaysBCoding/6e7b1f28c2507a41c8aa7b53000810d4 to your computer and use it in GitHub Desktop.
Save AlwaysBCoding/6e7b1f28c2507a41c8aa7b53000810d4 to your computer and use it in GitHub Desktop.
Ethereum Ðapp Development - Video 2 | Creating Ethereum Keypairs
// package.json
{
"dependencies": {
"web3": "0.17.0-alpha",
"ethereumjs-util": "4.5.0"
}
}
// keypairs.js
var EthUtil = require("ethereumjs-util")
var hexToBytes = function(hex) {
for (var bytes = [], c = 0; c < hex.length; c+=2)
bytes.push(parseInt(hex.substr(c, 2), 16));
return bytes;
}
var privateKeyToAddress = function(privateKey) {
return `0x${EthUtil.privateToAddress(hexToBytes(privateKey)).toString('hex')}`
}
console.log(privateKeyToAddress(process.argv[2]))
@agoldvarg
Copy link

Missing closing quote on line 10

@AlwaysBCoding
Copy link
Author

thanks @agoldvarg -- fixed now.

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