bitcoinjs / bitcoinjs-lib

A javascript Bitcoin library for node.js and browsers.
MIT License
5.6k stars 2.08k forks source link

TypeError: x.getPublicKeyBuffer is not a function #1163

Closed bellaj closed 5 years ago

bellaj commented 5 years ago

I am trying to use the code below :

var bitcoin = require("bitcoinjs-lib");
var keyPairs = [ 
     '91avARGdfge8E4tZfYLoxeJ5sGBdNJQH4kvjJoQFacbgwmaKkrx', 
     '91avARGdfge8E4tZfYLoxeJ5sGBdNJQH4kvjJoQFacbgww7vXtT', 
     '91avARGdfge8E4tZfYLoxeJ5sGBdNJQH4kvjJoQFacbgx3cTMqe', 
     '91avARGdfge8E4tZfYLoxeJ5sGBdNJQH4kvjJoQFacbgx9rcrL7' 
   ].map(function (wif) { return bitcoin.ECPair.fromWIF(wif, bitcoin.networks.testnet) }) 
   var pubKeys = keyPairs.map(function (x) { return x.getPublicKeyBuffer() }) 

   var redeemScript = bitcoin.script.multisig.output.encode(2, pubKeys) 
   var scriptPubKey = bitcoin.script.scriptHash.output.encode(bitcoin.crypto.hash160(redeemScript)) 
   var address = bitcoin.address.fromOutputScript(scriptPubKey, regtest) 

but i get the error:

   var pubKeys = keyPairs.map(function (x) { return x.getPublicKeyBuffer() }) 
                                                      ^
TypeError: x.getPublicKeyBuffer is not a function
dabura667 commented 5 years ago

change x.getPublicKeyBuffer() to x.publicKey