Exercise 1: Medium
In this exercise, you'll construct a P2MS (Pay-to-Multisig) ScriptPubKey within a P2SH (Pay-to-Script-Hash) for given public keys within a partially constructed transaction.
Here's a breakdown of the partially constructed transaction:
Field | Value |
---|---|
Version | 01000000 |
Input Count | 01 |
Input TXID | 97211e92d9590b4111a60f24f2c97eba2884bb813515a3167c634a9dcd113338 |
Input VOUT | 01000000 |
ScriptSig Size | N/A |
ScriptSig | N/A |
Sequence | ffffffff |
Output Count | 02 |
Output1 Amount | 8023430000000000 |
Output1 ScriptPubKey Size | 17 |
Output1 ScriptPubKey | N/A |
Output2 Amount | 00e1f50500000000 |
Output2 ScriptPubKey Size | 17 |
Output2 ScriptPubKey | a91482b736e28a94f42164db1fe448086f74725ae46487 |
Locktime | 00000000 |
The hexadecimal representation of this transaction is:
1010000000197211e92d9590b4111a60f24f2c97eba2884bb813515a3167c634a9dcd11333801000000-[signature]-ffffffff028023430000000000-[scriptPubKey1]-00e1f5050000000017a91482b736e28a94f42164db1fe448086f74725ae4648700000000
Exercise
Your task is to complete the constructP2MSP2SHScriptPubKey
function which creates a P2SH ScriptPubKey for a 2-of-2 multisig redeem script using the following public keys:
02632178d046673c9729d828cfee388e121f497707f810c131e0d3fc0fe0bd66d6
03a0951ec7d3a9da9de171617026442fcd30f34d66100fab539853b43f508787d4
Ready to Code?
Choose your preferred language to begin
You can look up the hex characters for each op_code in the Bitcoin Script wiki page.
- Start by creating the multisig redeem script: OP_2 <pubkey1> <pubkey2> OP_2 OP_CHECKMULTISIG
- Convert the redeem script to bytes
- Hash the redeem script using SHA256 and then RIPEMD160
- Create the P2SH script: OP_HASH160 <20-byte-hash> OP_EQUAL
- Return the final script as a hexadecimal string
Solution code
Inspiration
After completing the exercise, you can check out these testnet transactions to see real P2MS-in-P2SH ScriptPubKeys in action:
These transactions demonstrate how P2MS-in-P2SH ScriptPubKeys are used in actual Bitcoin transactions on the testnet.