<p>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.</p>
<p>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.</p>

CC BY-SA 4.0
2023-02-25T19:56:58.927Z
2023-02-26T11:05:37.050Z
2023-02-26T11:05:37.050Z
Pieter Wuille
<p>This code:</p>
<pre><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)
</code></pre>
<p>produces output:</p>
<pre><code>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
</code></pre>
<p>but Hash160 should give the sender address - the second and the third lines should be the same. What am I missing here?</p>

<bitcoin-core><wallet>
deriving address from pubkey API problem?
user140474
# deriving address from pubkey API problem?

(Asked by: username_0 on 2023-02-25)

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?

**Tags:** bitcoin-core, wallet


---

## 1 answers

### Answer by username_1 on 2023-02-25. Score: 2 | Accepted answer

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.


---

