Browse Source

README: Add P2SH Multisig example

hk-custom-address
Daniel Cousens 11 years ago
parent
commit
dcc9ddff08
  1. 17
      README.md

17
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

Loading…
Cancel
Save