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")

Require bitcoinjs-lib.

var keyPair = bitcoin.ECPair.makeRandom();

Make variable for keyPair.

console.log(keyPair.getAddress());

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.

console.log(keyPair.toWif());

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.