I installed bitcoinjs-lib with command: meteor npm install bitcoinjs-lib. The installation command "flow-typed install -f 0.27 bitcoinjs-lib@2.2.0" didn't work. No idea what flow-typed is and the influence it has.

This is the code I am running:

  import bip39 from 'bip39';
  import bip32 from 'bip32';
  import crypto from 'crypto';
  import bitcoin from 'bitcoinjs-lib';
  let randomBytes = crypto.randomBytes(32);
  this.mnemonic = "praise you muffin lion enable neck grocery crumble super myself license ghost"; //bip39.entropyToMnemonic(randomBytes.toString('hex'))
  this.seed = bip39.mnemonicToSeed(this.mnemonic); 
  console.log("seed:", bip39.mnemonicToSeed(this.mnemonic));

  let bitcoinNetwork = bitcoin.networks.bitcoin;
  var hdMaster = bip32.fromSeed(this.seed, bitcoinNetwork);

  const path = "m/0'/0/0";
  const child1 = hdMaster.derivePath(path);
  const { address } = bitcoin.payments.p2sh({
    redeem: bitcoin.payments.p2wpkh({ pubkey: child.publicKey, network: bitcoinNetwork }),
    network: bitcoinNetwork
  console.log("address: ", address);

Unfortunately bitcoin.payments is undefined. bitcoin.networks.bitcoin works ok.

Why is payments undefined? Thanks.


For some reason the isntalled bitcoinjs-lib didn't include the whole payments folder. I pasted it and then I modify index.js to include and now it works. I don't understand why the installation goes wrong.


The reason is you are using version 2.2.0 and paymentsis a feature newly added in version 4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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