Bitcoinjs-lib: Could not able to generate random KeyPair

Created on 28 Aug 2018  路  2Comments  路  Source: bitcoinjs/bitcoinjs-lib

Need Help, Why I am getting this Error???

TypeError: keyPair.getAddress is not a function
at Object. (/home/zohaib/real.js:12:26)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:191:16)
at bootstrap_node.js:612:3

My Code:

const Btc = require('bitcoinjs-lib');
const TestNet = Btc.networks.testnet;
let keyPair = Btc.ECPair.makeRandom({ network: TestNet });
let publicKey = keyPair.getAddress();
let privateKey = keyPair.toWIF;
console.log("Public: " + publicKey + " \nPrivate: " + privateKey);

how to / question / docs

Most helpful comment

maybe you should tell that ...

 var bitcoin = require('bitcoinjs-lib');
var keyPair = bitcoin.ECPair.makeRandom();
var publicKey = keyPair.publicKey
var { address } = bitcoin.payments.p2pkh({ pubkey: publicKey });
var privateKey = keyPair.toWIF();
console.log(address)
console.log(privateKey)

All 2 comments

You create an address like so

https://github.com/bitcoinjs/bitcoinjs-lib/blob/20551fd38070cf68d078c0644c7586a2607f57fa/test/integration/addresses.js#L22-L27

const Btc = require('bitcoinjs-lib');
const TestNet = Btc.networks.testnet;
let keyPair = Btc.ECPair.makeRandom({ network: TestNet });
let publicKey = keyPair.publicKey.toString('hex');
let { address } = Btc.payments.p2pkh({ pubkey: publicKey });
let privateKey = keyPair.toWIF();
console.log("Public: " + publicKey + " \nPrivate: " + privateKey + " \Address: " + address);

maybe you should tell that ...

 var bitcoin = require('bitcoinjs-lib');
var keyPair = bitcoin.ECPair.makeRandom();
var publicKey = keyPair.publicKey
var { address } = bitcoin.payments.p2pkh({ pubkey: publicKey });
var privateKey = keyPair.toWIF();
console.log(address)
console.log(privateKey)
Was this page helpful?
0 / 5 - 0 ratings

Related issues

panpan2 picture panpan2  路  3Comments

dakk picture dakk  路  3Comments

askucher picture askucher  路  3Comments

Beardcoding picture Beardcoding  路  3Comments

LeonYanghaha picture LeonYanghaha  路  3Comments