README: Add P2SH Multisig example

This commit is contained in:
Daniel Cousens 2014-07-10 13:48:54 +10:00
parent 27389d6d95
commit dcc9ddff08

View file

@ -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