From dcc9ddff0891c2ed467e7d3951027d1e5ac77a75 Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Thu, 10 Jul 2014 13:48:54 +1000 Subject: [PATCH] README: Add P2SH Multisig example --- README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/README.md b/README.md index e097492..56599fc 100644 --- a/README.md +++ b/README.md @@ -106,6 +106,23 @@ console.log(tx.toHex()) // You could now push the transaction onto the Bitcoin network manually (see https://blockchain.info/pushtx) ``` +### Creating a P2SH Multsig Address + +``` javascript +var bitcoin = require('bitcoinjs-lib') + +var privKeys = [bitcoin.ECKey.makeRandom(), bitcoin.ECKey.makeRandom(), bitcoin.ECKey.makeRandom()] +var pubKeys = privKeys.map(function(x) { return x.pub }) + +var redeemScript = bitcoin.scripts.multisigOutput(2, pubKeys) // 2 of 3 +var scriptPubKey = bitcoin.scripts.scriptHashOutput(redeemScript.getHash()) + +var multisigAddress = bitcoin.Address.fromOutputScript(scriptPubKey).toString() + +console.log("multisigP2SH:", multisigAddress) +``` + + ## Projects utilizing BitcoinJS