Bitcoin – Bitcoinjs and Private Keys

September 13, 2018

Author: Michael Gord

Tutorial - MLG Blockchain

Bitcoinjs and Private Keys

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.


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.

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. View all our blockchain development tutorials at

MLG Blockchain