Skip to main content
added 419 characters in body
Source Link
Ugam Kamat
  • 7.5k
  • 2
  • 15
  • 40

The first example that you have shown is a P2PKH address. The 0x14 indicates how many bytes to push onto the stack. 0x14 is 20 in decimal so the script pushes the next 20 bytes on the stack which is 6d 1d 74 58 95 6e 80 cd b4 c3 3f 1e d5 8e 91 c4 92 1a 85 d0.

The second case is a Pay to Script Hash example (P2SH). The script is HASH160 Push 20 bytes <redeem_script> OP_EQUAL>. Hence your redeem script in the second case is 16523302f2eed0e0aa6a4c1d0a41396fc26f536e. You would need to then Base58Check it with prefix of 0x05, this gives you the address as 33j3G4xMEn4CtKL5iYnsr97ww67wYh8TPY.

Below is the python script that gives you the address:

import base58
from hashlib import sha256

redeem_script = '16523302f2eed0e0aa6a4c1d0a41396fc26f536e'
version = '05'
payload = version + redeem_script
checksum = sha256(sha256(bytes.fromhex(payload)).digest()).hexdigest()[:8]

pre_encoded_address = payload + checksum
address = base58.b58encode(bytes.fromhex(pre_encoded_address)).decode()

The first example that you have shown is a P2PKH address. The 0x14 indicates how many bytes to push onto the stack. 0x14 is 20 in decimal so the script pushes the next 20 bytes on the stack which is 6d 1d 74 58 95 6e 80 cd b4 c3 3f 1e d5 8e 91 c4 92 1a 85 d0.

The second case is a Pay to Script Hash example (P2SH). The script is HASH160 Push 20 bytes <redeem_script> OP_EQUAL>. Hence your redeem script in the second case is 16523302f2eed0e0aa6a4c1d0a41396fc26f536e. You would need to then Base58Check it with prefix of 0x05, this gives you the address as 33j3G4xMEn4CtKL5iYnsr97ww67wYh8TPY

The first example that you have shown is a P2PKH address. The 0x14 indicates how many bytes to push onto the stack. 0x14 is 20 in decimal so the script pushes the next 20 bytes on the stack which is 6d 1d 74 58 95 6e 80 cd b4 c3 3f 1e d5 8e 91 c4 92 1a 85 d0.

The second case is a Pay to Script Hash example (P2SH). The script is HASH160 Push 20 bytes <redeem_script> OP_EQUAL>. Hence your redeem script in the second case is 16523302f2eed0e0aa6a4c1d0a41396fc26f536e. You would need to then Base58Check it with prefix of 0x05, this gives you the address as 33j3G4xMEn4CtKL5iYnsr97ww67wYh8TPY.

Below is the python script that gives you the address:

import base58
from hashlib import sha256

redeem_script = '16523302f2eed0e0aa6a4c1d0a41396fc26f536e'
version = '05'
payload = version + redeem_script
checksum = sha256(sha256(bytes.fromhex(payload)).digest()).hexdigest()[:8]

pre_encoded_address = payload + checksum
address = base58.b58encode(bytes.fromhex(pre_encoded_address)).decode()
Source Link
Ugam Kamat
  • 7.5k
  • 2
  • 15
  • 40

The first example that you have shown is a P2PKH address. The 0x14 indicates how many bytes to push onto the stack. 0x14 is 20 in decimal so the script pushes the next 20 bytes on the stack which is 6d 1d 74 58 95 6e 80 cd b4 c3 3f 1e d5 8e 91 c4 92 1a 85 d0.

The second case is a Pay to Script Hash example (P2SH). The script is HASH160 Push 20 bytes <redeem_script> OP_EQUAL>. Hence your redeem script in the second case is 16523302f2eed0e0aa6a4c1d0a41396fc26f536e. You would need to then Base58Check it with prefix of 0x05, this gives you the address as 33j3G4xMEn4CtKL5iYnsr97ww67wYh8TPY