blockchainbitcoinpublic-key

How to Create P2SH Address From Multiple Public Keys


this is what i tried:

  1. i created a reedem script : [OP_2, PB1 Length(1-byte), PB1, PB2 Length(1-byte), PB2, PB3 Length(1-byte), PB3, 83 (OP_3), 174 (OP_CHECKMULTISIG)]

  2. Hash = calcualte ripemd160 of sha256 of reedem script

  3. script_pubkey = [OP_160, Hash, OP_EQUAL]

after step 3 i don't know what to do to get the address. i know that the step 5 will be the base58 of step 4 and i don't know what is it. i saw some sources from python libraries but i could not figure out what they do.

so what is the step 4? thanks.


Solution

  • Step 4 involves prefixing the RIPEMD160(SHA256) hash of the redeem script with a network-specific version byte (note it differs for mainnet and testnet). For a P2SH address on the Bitcoin mainnet, you prefix the hash with the byte 0x05. This step is crucial as it denotes the address type and network. The complete data structure before Base58Check encoding will be: [version byte] + [Hash].

    After prefixing, next step includes Base58Check encoding, which includes calculating a checksum by taking the first four bytes of the SHA256(SHA256([version byte] + [Hash])) and appending them to the end of [version byte] + [Hash]. The entire structure is then encoded in Base58 to produce the final address.