<p>The PKH is for verifying the authenticity of a signed transaction. We couldn't convert it to the bech32 wallet address. Hashing is a one-way function. It means that if you hash a piece of data, it is impossible to revert the hash to its original form.</p>
<p>For instance, we consider a simple function used to get the modulus of 3 and a list of the input value</p>
<pre><code>1 `mod` 3 = 1
2 `mod` 3 = 2
3 `mod` 3 = 3
4 `mod` 3 = 1
</code></pre>
<p>In this example, the list of the input value is [1,2,3,4] and the list of hash results is [1,2,3,1]. So the 1 can be from 1, 4, 7, and so on. This is for the demonstration only, In practice hash functions shouldn't result in a small range of values like this.</p>

CC BY-SA 4.0
2023-04-16T23:28:45.410Z
2023-04-16T23:28:45.410Z
manhdt
<p>You can use <a href="https://github.com/Python-Cardano/pycardano" rel="nofollow noreferrer">pycardano</a> to derive the address from a public key file.</p>
<p>Example:</p>
<pre><code>from pycardano import Key, Address, Network

pk = Key.load(&quot;/path/to/payment.vkey&quot;)
pkh = pk.hash()
addr = Address(payment_part=pkh, Network.MAINNET)
print(addr)
</code></pre>
<p>If you already have the public key hash, use the following code to get pkh:</p>
<pre><code>from pycardano import VerificationKeyHash
pkh = VerificationKeyHash(bytes.fromhex(&quot;1234abcd...&quot;))
</code></pre>
<p>You can learn more about key and address manipulations in this page: <a href="https://pycardano.readthedocs.io/en/latest/guides/address.html" rel="nofollow noreferrer">https://pycardano.readthedocs.io/en/latest/guides/address.html</a></p>

CC BY-SA 4.0
2022-11-17T22:35:58.200Z
2022-11-17T22:35:58.200Z
Jerry
<p>I need a <code>bech32</code> wallet address and all that I have is my wallet <code>PKH</code> and a wallet <code>Id</code>. Is there a way to derive that <code>bech32</code> address in python?</p>
<p>Needed to perform queries on blockfrost and find how much amount of ADA I have in my wallet.</p>

<cardano-cli><wallet><bech32>
Obtain a wallet address from PKH and wallet ID in python?
# Obtain a wallet address from PKH and wallet ID in python?

(Asked by: username_0 on 2022-10-25)

I need a `bech32` wallet address and all that I have is my wallet `PKH` and a wallet `Id`. Is there a way to derive that `bech32` address in python?

Needed to perform queries on blockfrost and find how much amount of ADA I have in my wallet.

**Tags:** cardano-cli, wallet, bech32

---

## 2 answers

### Answer by username_2 on 2022-11-17. Score: 0 | Accepted answer

You can use pycardano to derive the address from a public key file.
Example:
from pycardano import Key, Address, Network

pk = Key.load("/path/to/payment.vkey")
pkh = pk.hash()
addr = Address(payment_part=pkh, Network.MAINNET)
print(addr)

If you already have the public key hash, use the following code to get pkh:
from pycardano import VerificationKeyHash
pkh = VerificationKeyHash(bytes.fromhex("1234abcd..."))

You can learn more about key and address manipulations in this page: https://pycardano.readthedocs.io/en/latest/guides/address.html


---

### Answer by username_1 on 2023-04-16. Score: 1

The PKH is for verifying the authenticity of a signed transaction. We couldn't convert it to the bech32 wallet address. Hashing is a one-way function. It means that if you hash a piece of data, it is impossible to revert the hash to its original form.
For instance, we consider a simple function used to get the modulus of 3 and a list of the input value
1 `mod` 3 = 1
2 `mod` 3 = 2
3 `mod` 3 = 3
4 `mod` 3 = 1

In this example, the list of the input value is [1,2,3,4] and the list of hash results is [1,2,3,1]. So the 1 can be from 1, 4, 7, and so on. This is for the demonstration only, In practice hash functions shouldn't result in a small range of values like this.


---

