Bitcoinjs-lib: What should i do for getting privatekey?

Created on 18 Oct 2018  路  3Comments  路  Source: bitcoinjs/bitcoinjs-lib

I have generated address see the below code..

'use strict'

var bip39 = require('bip39');
var bip32 = require('bip32');
var bitcoin = require('bitcoinjs-lib');

function getAddress (node, network) {
  return bitcoin.payments.p2pkh({ pubkey: node.publicKey, network }).address
}

var mnemonic = bip39.generateMnemonic();
if (bip39.validateMnemonic(mnemonic)) {
    console.log('\nThe mnemonic is \n' + mnemonic);
    var seed = bip39.mnemonicToSeed(mnemonic);
    var root = bip32.fromSeed(seed);
    var dp = root.derivePath("m/140'/0'/0'/0/5");
    console.log(dp.privateKey);  // I used dp.privateKey but this not returning privatekey
    console.log('\nThe Address is \n' + getAddress(dp));    
} else {

}
Output:

$ node index.js

The mnemonic is
assume victory kiwi swarm furnace firm thumb exact dizzy crucial neglect certain

The Address is
1FYtPnUZZ2ZJL2fZ6XehGtkHfujUHkqK3T

Help me to get privatekey for this address 1FYtPnUZZ2ZJL2fZ6XehGtkHfujUHkqK3T
tell me what should I do for getting privatekey for the above address I have generated
I used dp.privateKey but this not returning privatekey

how to / question / docs

All 3 comments

It works for me. I just copy pasted your code and it gives me the private key.

What version?

What environment?

By the way, your private key for 1FYtPnUZZ2ZJL2fZ6XehGtkHfujUHkqK3T is below.

Buffer.from('4dc8579ae9cb65a8afe146325007caec44a39997f248f9c9579d90937e783737', 'hex')

yeah thanks its working

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zhaozhiming picture zhaozhiming  路  3Comments

askucher picture askucher  路  3Comments

dakk picture dakk  路  3Comments

Mr-Mondragon picture Mr-Mondragon  路  3Comments

itsMikeLowrey picture itsMikeLowrey  路  3Comments