I have the following example, on which I admit I am stuck:

Bob sends 0.5 BTC to Carla, who is the owner of a P2SH address of the form 3xxxxxx.

For Carla to spend the 0.5 BTC and pay Josh, who also has a 3xxxxxx P2SH address, she needs the redeemScript from Bob.

Let's say she has that from Bob and Carla sends to Josh the 0.5 BTC. Now we have a TRXO of 0.5 which can be seen on blockchain explorer under Josh's address.

To spend the TRXO, Josh also needs the redeemScript, right? Is it the same one as Bob's redeemScript?

According to Andreas's book, the redeemScript required for spending from a P2SH address is revealed after the first Output spent from the funding address.

So simply by looking at the scriptSig: under Bob's INPUT (e.g. PUSHDATA(66)[xxxxxxxxxxxxxxxxxxxxx], and taking the redeemScript from there anyone can hash that and spend the 0.5 BTC? If so, how?

The TRXO is not based on publickey as in the case of addresses of the form 1xxxx so it's not associated with Josh's address but rather with anyone who can produce a hash of the redeemScript.

This below explains a lot in previous chapters but the practical side of the article is still in draft.


The [draft] side is what I want to understand. I think this is very important because many addresses are P2SH these days. Most are multisig, yes, very secure. But if it's not multisig, isn't it a vulnerability to access the redeemScript just by looking at a previous TRX INPUT?

I use Node JS and can access libs, on Windows + Bitcoin core.I want to test these on testnet and maybe with a small amount on Livenet.



1 Answer 1


bitcoinjs-lib has examples for multisig P2SH, single-key Segwit wrapped in P2SH, and multisig Segwit wrapped in P2SH.

  • Thanks! I think this is what I am looking for github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/…. So this is how you create a P2SH address from the redeemScript hashed? Also it says 'bitcoin.ECPair.fromWIF('cMahea7zqjxrtgAbB7LSGbcQUr1uX1ojuat9jZodMN87JcbXMTcA' The WIF is the redeemScript between ''?
    – Robert
    Commented Jun 15, 2018 at 13:44
  • Multisig addresses still require private keys. Here, you have multiple private keys in WIF, which are used to build a redeem script (a multisig redeem script is just m <pubkeys> n OP_CHECKMULTISIG for an m of n multisig, so you can derive the public keys from the private key. Commented Jun 15, 2018 at 13:58
  • I understand multisig. That's not what I meant. I am referring to TRXO looking like HASH160 PUSHDATA(20)[xxxxxxxxxxxxx] EQUAL, no multisig required.
    – Robert
    Commented Jun 15, 2018 at 14:03
  • That's the locking script for the output. When combined with the signatures and redeem script, it forms a complete script. In essence, the signatures following by the redeem script will first check that the multisig requirements are met. Then, the redeemscript is HASH160'd, which is then compared to the push(20) to ensure that the redeem script corresponds to the address Commented Jun 15, 2018 at 14:05
  • I see but my question is about non-multisigs. I am trying understand TRXO's of the "type": "scripthash" NOT type": "multyisig". How are those making use of the redeemScript?
    – Robert
    Commented Jun 15, 2018 at 14:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.