Skip to content

Commit dcc9ddf

Browse files
committed
README: Add P2SH Multisig example
1 parent 27389d6 commit dcc9ddf

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

README.md

+17
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,23 @@ console.log(tx.toHex())
106106
// You could now push the transaction onto the Bitcoin network manually (see https://blockchain.info/pushtx)
107107
```
108108

109+
### Creating a P2SH Multsig Address
110+
111+
``` javascript
112+
var bitcoin = require('bitcoinjs-lib')
113+
114+
var privKeys = [bitcoin.ECKey.makeRandom(), bitcoin.ECKey.makeRandom(), bitcoin.ECKey.makeRandom()]
115+
var pubKeys = privKeys.map(function(x) { return x.pub })
116+
117+
var redeemScript = bitcoin.scripts.multisigOutput(2, pubKeys) // 2 of 3
118+
var scriptPubKey = bitcoin.scripts.scriptHashOutput(redeemScript.getHash())
119+
120+
var multisigAddress = bitcoin.Address.fromOutputScript(scriptPubKey).toString()
121+
122+
console.log("multisigP2SH:", multisigAddress)
123+
```
124+
125+
109126

110127
## Projects utilizing BitcoinJS
111128

0 commit comments

Comments
 (0)