0

What are the contents of a redeem script hash in a p2sh transaction?

From what i read it's similar to the pubkey script but does it only contain the receiver's address?

0
1

1. Bitcoin single signature P2SH:

RedeemScript Template = “[PubKey] OP_CHECKSIG”

Working Examples:

% echo "[020ae29f86f404e4b302cfa17ff15d93149af6a54c80a4172d47e41f55f6a78d73] checksig" | bx script-encode

21020ae29f86f404e4b302cfa17ff15d93149af6a54c80a4172d47e41f55f6a78d73ac (Script)

% echo "[020ae29f86f404e4b302cfa17ff15d93149af6a54c80a4172d47e41f55f6a78d73] checksig" | bx script-encode | bx sha256 | bx ripemd160

49e266a68641d2caa6696b00696f00f0a5706350 (Hash Answer)

% echo "[020ae29f86f404e4b302cfa17ff15d93149af6a54c80a4172d47e41f55f6a78d73] checksig" | bx script-encode | bx sha256 | bx ripemd160 | bx base58check-encode -v 5

38RgUAR367PFbFFgS57BYcERHkpqHEMBvA (Address)

or more simply,

% echo "[020ae29f86f404e4b302cfa17ff15d93149af6a54c80a4172d47e41f55f6a78d73] checksig" | bx script-to-address -v 5

38RgUAR367PFbFFgS57BYcERHkpqHEMBvA

2. Bitcoin BIP16 multisig:

2 of 3 RedeemScript Template = "OP_2 [PubKey1] [PubKey2] [PubKey3] OP_3 OP_CHECKMULTISIG"

Working Examples:

% echo "2 [020ae29f86f404e4b302cfa17ff15d93149af6a54c80a4172d47e41f55f6a78d73] [03664d528eb80096671ef9011c533ceb5df133238e3690d88f2960c786398b86b1] [029a449ea4a2155ea10002d704604bb3e8606631d35af20889a74b82b2dab572f6] 3 checkmultisig" | bx script-encode

5221020ae29f86f404e4b302cfa17ff15d93149af6a54c80a4172d47e41f55f6a78d732103664d528eb80096671ef9011c533ceb5df133238e3690d88f2960c786398b86b121029a449ea4a2155ea10002d704604bb3e8606631d35af20889a74b82b2dab572f653ae (Script)

% echo "2 [020ae29f86f404e4b302cfa17ff15d93149af6a54c80a4172d47e41f55f6a78d73] [03664d528eb80096671ef9011c533ceb5df133238e3690d88f2960c786398b86b1] [029a449ea4a2155ea10002d704604bb3e8606631d35af20889a74b82b2dab572f6] 3 checkmultisig" | bx script-encode | bx bitcoin160

7e580c3a86432d96dd60784e99f5a94e463414fe (Hash Answer)

% echo "2 [020ae29f86f404e4b302cfa17ff15d93149af6a54c80a4172d47e41f55f6a78d73] [03664d528eb80096671ef9011c533ceb5df133238e3690d88f2960c786398b86b1] [029a449ea4a2155ea10002d704604bb3e8606631d35af20889a74b82b2dab572f6] 3 checkmultisig" | bx script-to-address -v 5

3DD4YP2T75TQtf84KrHzYVLYgNAeaHWqxq (Address)

3. Bitcoin P2WPKH-nested-in-P2SH:

RedeemScript Template = "0 [PubKey]"

Working Examples:

% echo "0 [020ae29f86f404e4b302cfa17ff15d93149af6a54c80a4172d47e41f55f6a78d73]" | bx script-encode

0021020ae29f86f404e4b302cfa17ff15d93149af6a54c80a4172d47e41f55f6a78d73 (Script)

% echo "0 [020ae29f86f404e4b302cfa17ff15d93149af6a54c80a4172d47e41f55f6a78d73]" | bx script-encode | bx bitcoin160

7138cbb443e9ed635d3dd02a3e450884e3f9f0c8 (Hash Answer)

% echo "0 [020ae29f86f404e4b302cfa17ff15d93149af6a54c80a4172d47e41f55f6a78d73]" | bx script-to-address -v 5

3C1gKTRSAwSLj8Ft1eYooLkWxwJ5cqDdpb (Address)

0

currently the most use case for P2SH tx are multisig constructions. They usually contain s.th. like this:

OP_2 <Pubkey1> <Pubkey2> <Pubkey3> OP_3 OP_CHECKMULTISIG

This is a 2-of-3 multisig redeemscript, which is then hashed, and returns on mainnet an address starting with "3". It does not contain the receiver address, it contains the public keys.

Looking a bit in the forum on P2SH and multisig, you find useful info, and of course multisig is not the only use case for P2SH. Smart contracts are also a common usage. I recommend reading the developer examples and references for multisig p2sh, and also Andreas' book "Mastering Bitcoin". Here especially chapter 7 on advanced transactions. It is an amazing book that'll definitely get you started. It's freely available online here.

1
  • Another example is for BIP 49 P2WPKH-nested-in-P2SH redemptions (currently used by Trezor segwit-enabled devices), i.e. OP_0 <HASH160(Pubkey)> – skaht Jul 31 '18 at 15:24

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