README: Add P2SH Multisig example
This commit is contained in:
parent
27389d6d95
commit
dcc9ddff08
1 changed files with 17 additions and 0 deletions
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)
|
// 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
|
## Projects utilizing BitcoinJS
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue