How to Generate a New Bitcoin Address and Private Key
You must have node and npm downloaded on your computer. After this tutorial you should have both a public bitcoin address and private key saved as variables.
npm install bitcoinjs-lib
Download bitcoinjs library from your node terminal.
var bitcoin = require("bitcoinjs-lib")
var keyPair = bitcoin.ECPair.makeRandom();
Make variable for keyPair.
Test address by logging address to console. A valid bitcoin address should be returned.
var address = keyPair.getAddress();
Save bitcoin address result to a variable.
Test private key by logging to console. A valid bitcoin private key should be returned.
var pkey = keyPair.toWIF();
Save bitcoin private key result to a variable.
Disclaimer: The author is the founder of MLG Blockchain. This tutorial was originally published on MLG Blockchain.
MLG Blockchain is a blockchain development and consulting firm based in Toronto that is focused on building next generation applications using blockchain and smart contract technology. See more blockchain development tutorials on the MLG Blockchain blog.
Don't miss a story
Subscribe to our email newsletter:
Don't worry we hate spam as much as you do