Skip to content

Instantly share code, notes, and snippets.

@bkawk
Last active June 14, 2016 06:05
Show Gist options
  • Save bkawk/86b015f2be16cfe3046c99c4036e6637 to your computer and use it in GitHub Desktop.
Save bkawk/86b015f2be16cfe3046c99c4036e6637 to your computer and use it in GitHub Desktop.
Make a bitcoin address and WIF
var bitcoin = require('bitcoinjs-lib')
var fs = require("fs")
function randomString(length, chars) {
var result = '';
for (var i = length; i > 0; --i) result += chars[Math.floor(Math.random() * chars.length)];
return result;
}
function makePair(params) {
var rand = randomString(32, '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ');
function rng () { return new Buffer(rand) }
var keyPair = bitcoin.ECPair.makeRandom({ rng: rng })
var address = keyPair.getAddress();
var wif = keyPair.toWIF();
console.log('Address: '+address);
console.log('WIF: '+wif);
}
(function () {
makePair();
})();
{
"name": "KeyPair",
"version": "1.0.0",
"description": "Make a bitcoin address and WIF",
"main": "index.js",
"scripts": {
"start": "nodemon index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Will In China @bkawk",
"license": "MIT",
"dependencies": {
"bitcoinjs-lib": "^2.2.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment