different multisig address from the same public keys

1

1

When I use bitcoin-cli -testnet to generate a 2-of-3 address, the code:

bitcoin-cli -testnet createmultisig 2 '''
 [
   "03b91ff254ae3bb3861e4a6c16ab356d6c52ccfd2b58bedf0dda84657dfd9d9afc",
   "039f1475fb37d91ed65765c897acbdc37da3a7aba19f5b8ad5ff22a994e8350798", 
   "030ee8793fa2cb93f0cfd475b990cbaa48a28d83bd8f434348607368e52644febf"
 ]'''

the result is

"address": "2MzSwUwBc1xuNHwRotwrdFugLvju8VV9uPT",

But when I use bitcoinjs-lib, the code is:

var pubKeys = [
'03b91ff254ae3bb3861e4a6c16ab356d6c52ccfd2b58bedf0dda84657dfd9d9afc',
'039f1475fb37d91ed65765c897acbdc37da3a7aba19f5b8ad5ff22a994e8350798',
'030ee8793fa2cb93f0cfd475b990cbaa48a28d83bd8f434348607368e52644febf'
].map(function(hex){
return new Buffer(hex, 'hex');
});


var redeemScript = bitcoin.script.multisig.output.encode(2, pubKeys); // 2 of 3
var scriptPubkey = bitcoin.script.scriptHash.output.encode(bitcoin.crypto.hash160(redeemScript));
var address = bitcoin.address.fromOutputScript(scriptPubkey);

Now the address changed to

38tjRCFaQWQ269oGDpEkdxh5iPgxh7kvtB

How could this happen? Did I do something wrong?

Peili Liang

Posted 2017-08-31T08:03:42.773

Reputation: 78

Answers

3

you run bitcoinjs-lib in main-net mode and it generates the human-readable address for main-net

bitcoin-cli you execute with -testnet parameter and got address for test-net

you can check that these hashes are the same:

https://testnet.smartbit.com.au/tx/8c67e4d3264696d222d5a72c70c8806eb3f12b9a02d1bc80554ab00803be86c0

https://blockchain.info/address/38tjRCFaQWQ269oGDpEkdxh5iPgxh7kvtB

both are 4f0017ef9291b625bec1d7efacc246a37b293682

amaclin

Posted 2017-08-31T08:03:42.773

Reputation: 5 763

1Thanks for your answer. I want upvote your answer but I don't have enough reputations. Thanks again.Peili Liang 2017-08-31T08:28:34.473