0

This code:

sender_public_key = sender_private_key.pub
sender_address = P2PKHBitcoinAddress.from_pubkey(sender_public_key)

print(sender_public_key)
print(bitcoin.core.Hash160(sender_public_key))
print(sender_address)

produces output:

CPubKey(b'\x033\xad\xcb\xe4r\xe6\xef\x04\xa0I\x0f(B\x1c\x8a;@C\xa8\x99jo\x8a\x85\xd5\xee\x9e\xe2\x8a\x1f|q')
b'\x93\xa7\xc4E$\xa3\xcf{0\xfe\x91\xa6\xa3XR\xfav6\x80#'
mtygbtN2LZt3U5QcMNQF3Zq2sqJF4HowYm

but Hash160 should give the sender address - the second and the third lines should be the same. What am I missing here?

1 Answer 1

2

P2PKH (pay to public key hash) addresses do contain the same information as the 160 bit public key hash they correspond to, but they use a different encoding than is used for hashes typically.

Specifically, addresses use the Base58 encoding format (including a truncated double-SHA256 checksum and a version byte to indicate the type of address). Public keys and hashes are usually presented in hexadecimal.

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.