1

I installed bitcoinjs-lib with command: meteor npm install bitcoinjs-lib. The installation command "flow-typed install -f 0.27 [email protected]" 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.

educob
  • 19
  • 4
  • I found this link but I don't really understand what it says: https://github.com/bitcoinjs/bitcoinjs-lib/pull/1096/files/62125fe853d63875b427b2af1d7e6467dcad030e – educob Jul 13 '18 at 15:00

2 Answers2

0

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.

educob
  • 19
  • 4
0

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

timqian
  • 101
  • 3