<pre>from bitcoinlib.keys import *

pk = 567
address_U = Key(import_key=pk, network='bitcoin', compressed=False)
print(address_U.address())
print(address_U.public_hex)
print(address_U._x)
print(address_U._y)
print(address_U.hash160.hex())
print(address_U.wif())
print('***************')
address_C = Key(import_key=pk, network='bitcoin', compressed=True)
print(address_C.address())
print(address_C.public_hex)
print(address_C._x)
print(address_C._y)
print(address_C.hash160.hex())
print(address_C.wif())
print('***************')
print(Address(address_C.public_hex, encoding='base58', script_type='p2sh', witness_type='p2sh-segwit').address)
print(Address(address_C.public_hex, encoding='bech32', script_type='p2wpkh').address)
print(Address(address_C.public_hex, encoding='bech32', script_type='p2wsh').address)</pre>

CC BY-SA 4.0
2022-07-14T05:27:49.380Z
2022-07-14T05:28:27.730Z
2022-07-14T05:28:27.730Z
Alexander Curl
<p>I have a tool which does that in my <a href="https://github.com/nlitsme/python-bcutils/blob/master/bcaddr.py" rel="nofollow noreferrer">bcutils</a> repository:</p>
<pre><code>python3 bcaddr.py KwaZRh42fdQD4iUN6sy2GtEC5gfSAYXrQgp16KPV4Pxsspi5ChRb
privkey             : 0ab9bb56315ce08019d61dd3480e51c35d6339c4618ad5c9824d0e47bedcc957
wallet              : 5Hu1YsmBoMwCLsdZRSbSfVNZsTCt1oZpSkunncS2ptsitRnbe3m
cwallet             : KwaZRh42fdQD4iUN6sy2GtEC5gfSAYXrQgp16KPV4Pxsspi5ChRb
version: 128          compressed: 1
compressed          : 03418fe8f11fa50cd9584b290fcbfc60c5af9a713facf3faac27792921910dbd5a
full                : 04418fe8f11fa50cd9584b290fcbfc60c5af9a713facf3faac27792921910dbd5a7ccb3081ca2a2f06f2944b2405c622860af42ce5e91351f428c0199c6055dc85
comp: e7a078291dd17a57e8f03d325604d7f7193ce56a:   0 1N7jKvQ1fHezb61eNsGEaF4gcj5sQXhb2m - bc1qu7s8s2ga69a9068s85e9vpxh7uvneet292wa5n
full: 24c2e464c447a78950949c8649729865dd41e5e7:   0 14MNoFYWheu7sLkj8urvXCpYEdCuL4m2PH - bc1qynpwgexyg7ncj5y5njryju5cvhw5re08yvasde
p2sh: 9d92bd57e9a882fe08c200b8f325efecbb2cb2c0:   5 3G4BoJsFB6N3Eejtovr8PUnvz4LRDhWmxk - bc19nkft64lf4zp0uzxzqzu0xf00ajajevkqvgd0xt
p2sh(full): 6ce28aa65204eabc762e5adcc7b7146810a54bc0:   5 3BckHeXP5Gb6n5iXRepyDpWAVjXu58YRb4 - bc19dn3g4fjjqn4tca3wttwv0dc5dqg22j7qtkf620
p2wsh: 30fdfba51324d8ef36d1cbfb072af035dac0d7080fb8f13cb05ed5a474c09e84: - bc1qxr7lhfgnynvw7dk3e0asw2hsxhdvp4cgp7u0z09stm26gaxqn6zqd9muau
</code></pre>

CC BY-SA 4.0
2022-11-11T21:21:17.480Z
2022-11-11T21:21:17.480Z
Willem Hengeveld
<pre><code>from bitcoinlib.keys import *

priv_key = '0000000000000000000000000000000000000000000000000000000000000237'

U_pub_key = Key(import_key=priv_key, network='bitcoin', compressed=False)
C_pub_key = Key(import_key=priv_key, network='bitcoin', compressed=True)
C_hex = C_pub_key.public_hex

U_wif = U_pub_key.wif()
C_wif = C_pub_key.wif()

add_U = U_pub_key.address()
add_C = C_pub_key.address()

p2sh_segwit = Address(C_hex, encoding='base58', script_type='p2sh', witness_type='p2sh-segwit').address
p2wpkh = Address(C_hex, encoding='bech32', script_type='p2wpkh').address
p2wsh = Address(C_hex, encoding='bech32', script_type='p2wsh').address

print(add_U)
print(add_C)
print(p2sh_segwit)
print(p2wpkh)
print(p2wsh)
print(U_wif)
print(C_wif)
print(priv_key)
print(U_pub_key)
print(C_pub_key)
</code></pre>
<blockquote>
<pre><code>13sjRRtRsDD3gQVW2XDXHM8ahBEBzVNyrK
1KCvMjHxAKv7pdzCFLhhKrQNpVWN1eyeAb
32MAGHunMfYDb1cCC1hDxiovYCUg6oNxhU
bc1qc7ekz48gzmds2sedh9vm59j3yezg33d392fzj3
bc1qu4t4gt4dpzjhr357yxmnjjsqaakuc75vt8qhct9kgraq7pd7xgys8hw8eg
5HpHagT65TZzG1PH3CSu63k8DbpvD8s5ip4nEB3kEsrfGd4hTb9
KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFUBuithWYeP
0000000000000000000000000000000000000000000000000000000000000237
0455faaaee59a20b9a3784d1719ea529cc1b7ab3a329f26dfaa3b11bd667ba15c1a9f8939b52ac53e35ed4771d8e47065c0d7f2805a7e5475c37353ddf182f4a65
0355faaaee59a20b9a3784d1719ea529cc1b7ab3a329f26dfaa3b11bd667ba15c1
</code></pre>
</blockquote>

CC BY-SA 4.0
2023-04-14T05:42:58.467Z
2023-04-14T05:42:58.467Z
Micro 
<p>For the private key <code>KwaZRh42fdQD4iUN6sy2GtEC5gfSAYXrQgp16KPV4Pxsspi5ChRb</code>, I have the following addresses:</p>

<ul>
<li><code>1N7jKvQ1fHezb61eNsGEaF4gcj5sQXhb2m</code> (P2PKH)</li>
<li><code>14MNoFYWheu7sLkj8urvXCpYEdCuL4m2PH</code> (P2PKH)</li>
<li><code>3G4BoJsFB6N3Eejtovr8PUnvz4LRDhWmxk</code> (P2SH)</li>
<li><code>bc1qu7s8s2ga69a9068s85e9vpxh7uvneet292wa5n</code> (P2WPKH)</li>
<li><code>bc1qxr7lhfgnynvw7dk3e0asw2hsxhdvp4cgp7u0z09stm26gaxqn6zqd9muau</code> (P2WSH)</li>
</ul>

<p>I am looking for a utility (like the <code>ku</code> utility from <a href="https://github.com/richardkiss/pycoin" rel="nofollow noreferrer">https://github.com/richardkiss/pycoin</a>) which can generate all these address given the private key (the <code>ku</code> does not generate the P2WSH address). The utility I am searching for can be in C, C++, Go or Python.</p>

CC BY-SA 4.0
2020-02-24T11:45:56.597Z
https://godoc.org/github.com/btcsuite/btcutil ?
RedGrittyBrick
CC BY-SA 4.0
2020-02-24T11:57:09.750Z
@RedGrittyBrick Thanks but I already know about this one. Looking for a executable like `ku` so that I don't have to write any code.
GMaster
CC BY-SA 4.0
2022-07-14T12:55:24.433Z
It's not clear to me why you would generate a *SH address from a single key. Could you outline what sort of script that should contain?
Murch
<address><private-key><address-generation>
How to generate these bitcoin addresses?
GMaster
# How to generate these bitcoin addresses?

(Asked by: username_0 on 2020-02-24)

For the private key `KwaZRh42fdQD4iUN6sy2GtEC5gfSAYXrQgp16KPV4Pxsspi5ChRb`, I have the following addresses:

* `1N7jKvQ1fHezb61eNsGEaF4gcj5sQXhb2m` (P2PKH)
* `14MNoFYWheu7sLkj8urvXCpYEdCuL4m2PH` (P2PKH)
* `3G4BoJsFB6N3Eejtovr8PUnvz4LRDhWmxk` (P2SH)
* `bc1qu7s8s2ga69a9068s85e9vpxh7uvneet292wa5n` (P2WPKH)
* `bc1qxr7lhfgnynvw7dk3e0asw2hsxhdvp4cgp7u0z09stm26gaxqn6zqd9muau` (P2WSH)

I am looking for a utility (like the `ku` utility from <https://github.com/richardkiss/pycoin>) which can generate all these address given the private key (the `ku` does not generate the P2WSH address). The utility I am searching for can be in C, C++, Go or Python.

**Tags:** address, private-key, address-generation

> **Comments:**
> **username_1**: https://godoc.org/github.com/btcsuite/btcutil ?  
> **username_0**: @username_1 Thanks but I already know about this one. Looking for a executable like `ku` so that I don't have to write any code.  
> **username_2**: It's not clear to me why you would generate a *SH address from a single key. Could you outline what sort of script that should contain?  

---

## 3 answers

### Answer by username_3 on 2022-07-14. Score: 0

from bitcoinlib.keys import *

pk = 567
address_U = Key(import_key=pk, network='bitcoin', compressed=False)
print(address_U.address())
print(address_U.public_hex)
print(address_U._x)
print(address_U._y)
print(address_U.hash160.hex())
print(address_U.wif())
print('***************')
address_C = Key(import_key=pk, network='bitcoin', compressed=True)
print(address_C.address())
print(address_C.public_hex)
print(address_C._x)
print(address_C._y)
print(address_C.hash160.hex())
print(address_C.wif())
print('***************')
print(Address(address_C.public_hex, encoding='base58', script_type='p2sh', witness_type='p2sh-segwit').address)
print(Address(address_C.public_hex, encoding='bech32', script_type='p2wpkh').address)
print(Address(address_C.public_hex, encoding='bech32', script_type='p2wsh').address)


---

### Answer by username_4 on 2022-11-11. Score: 0

I have a tool which does that in my bcutils repository:
python3 bcaddr.py KwaZRh42fdQD4iUN6sy2GtEC5gfSAYXrQgp16KPV4Pxsspi5ChRb
privkey             : 0ab9bb56315ce08019d61dd3480e51c35d6339c4618ad5c9824d0e47bedcc957
wallet              : 5Hu1YsmBoMwCLsdZRSbSfVNZsTCt1oZpSkunncS2ptsitRnbe3m
cwallet             : KwaZRh42fdQD4iUN6sy2GtEC5gfSAYXrQgp16KPV4Pxsspi5ChRb
version: 128          compressed: 1
compressed          : 03418fe8f11fa50cd9584b290fcbfc60c5af9a713facf3faac27792921910dbd5a
full                : 04418fe8f11fa50cd9584b290fcbfc60c5af9a713facf3faac27792921910dbd5a7ccb3081ca2a2f06f2944b2405c622860af42ce5e91351f428c0199c6055dc85
comp: e7a078291dd17a57e8f03d325604d7f7193ce56a:   0 1N7jKvQ1fHezb61eNsGEaF4gcj5sQXhb2m - bc1qu7s8s2ga69a9068s85e9vpxh7uvneet292wa5n
full: 24c2e464c447a78950949c8649729865dd41e5e7:   0 14MNoFYWheu7sLkj8urvXCpYEdCuL4m2PH - bc1qynpwgexyg7ncj5y5njryju5cvhw5re08yvasde
p2sh: 9d92bd57e9a882fe08c200b8f325efecbb2cb2c0:   5 3G4BoJsFB6N3Eejtovr8PUnvz4LRDhWmxk - bc19nkft64lf4zp0uzxzqzu0xf00ajajevkqvgd0xt
p2sh(full): 6ce28aa65204eabc762e5adcc7b7146810a54bc0:   5 3BckHeXP5Gb6n5iXRepyDpWAVjXu58YRb4 - bc19dn3g4fjjqn4tca3wttwv0dc5dqg22j7qtkf620
p2wsh: 30fdfba51324d8ef36d1cbfb072af035dac0d7080fb8f13cb05ed5a474c09e84: - bc1qxr7lhfgnynvw7dk3e0asw2hsxhdvp4cgp7u0z09stm26gaxqn6zqd9muau


---

### Answer by username_5 on 2023-04-14. Score: 0

from bitcoinlib.keys import *

priv_key = '0000000000000000000000000000000000000000000000000000000000000237'

U_pub_key = Key(import_key=priv_key, network='bitcoin', compressed=False)
C_pub_key = Key(import_key=priv_key, network='bitcoin', compressed=True)
C_hex = C_pub_key.public_hex

U_wif = U_pub_key.wif()
C_wif = C_pub_key.wif()

add_U = U_pub_key.address()
add_C = C_pub_key.address()

p2sh_segwit = Address(C_hex, encoding='base58', script_type='p2sh', witness_type='p2sh-segwit').address
p2wpkh = Address(C_hex, encoding='bech32', script_type='p2wpkh').address
p2wsh = Address(C_hex, encoding='bech32', script_type='p2wsh').address

print(add_U)
print(add_C)
print(p2sh_segwit)
print(p2wpkh)
print(p2wsh)
print(U_wif)
print(C_wif)
print(priv_key)
print(U_pub_key)
print(C_pub_key)


13sjRRtRsDD3gQVW2XDXHM8ahBEBzVNyrK
1KCvMjHxAKv7pdzCFLhhKrQNpVWN1eyeAb
32MAGHunMfYDb1cCC1hDxiovYCUg6oNxhU
bc1qc7ekz48gzmds2sedh9vm59j3yezg33d392fzj3
bc1qu4t4gt4dpzjhr357yxmnjjsqaakuc75vt8qhct9kgraq7pd7xgys8hw8eg
5HpHagT65TZzG1PH3CSu63k8DbpvD8s5ip4nEB3kEsrfGd4hTb9
KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFUBuithWYeP
0000000000000000000000000000000000000000000000000000000000000237
0455faaaee59a20b9a3784d1719ea529cc1b7ab3a329f26dfaa3b11bd667ba15c1a9f8939b52ac53e35ed4771d8e47065c0d7f2805a7e5475c37353ddf182f4a65
0355faaaee59a20b9a3784d1719ea529cc1b7ab3a329f26dfaa3b11bd667ba15c1


---

