I am getting Getting error at this line
var root = bitcoin.HDNode.fromSeedBuffer(seed);

UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'fromSeedBuffer' of undefined

Here is the code snippet to generate bitcoin address:

'use strict'

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

var mnemonic = bip39.generateMnemonic();
if (bip39.validateMnemonic(mnemonic)) {
    console.log('\nThe mnemonic is \n' + mnemonic);
    var seed = bip39.mnemonicToSeed(mnemonic);
    var root = bitcoin.HDNode.fromSeedBuffer(seed);
    var dp = root.derivePath("m/140'/0'/0'/0/5");

    console.log('\nThe Address is \n' + dp.getAddress());    
} else {

}

Where bitcoinjs-lib v4.0.0 and bip39 v2.5.0 and node v8.0

Try using the bip32 module. Also there are a few other things you'll need to fix as well. See Use BIP39 to generate BIP32 addresses. Note, this will generate a P2PKH address, see getAddress() function.

index.js:

'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('\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

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.