Post
Topic
Board Development & Technical Discussion
Merits 7 from 4 users
Re: Hex privete key to all Bitcoin addresses, python script?
by
PowerGlove
on 10/12/2023, 23:39:18 UTC
⭐ Merited by bitmover (2) ,pooya87 (2) ,hosseinimr93 (2) ,mocacinno (1)
Does any one have or know a python script that convert Hex private key to all Bitcoin addresses (...)
Yup, I wrote one a while back; here's the post: Generating addresses from scratch (Python 3.6+).

It doesn't cover all of the address types you're after, but I'm sure you'll find it useful nonetheless (it'll show compressed-P2PKH and P2WPKH addresses by default, but you can get it to show uncompressed-P2PKH addresses too by going to the top of the script and changing show_p2pkh_uncompressed to True).

Here's how you would invoke it (with your example private key):

Code:
$ python3 make_address.py 0x3902e4f09664bc177fe4e090dcd9906b432b50f15fb6151984475c1c75c35b6

And here's the output (after having adjusted show_p2pkh_uncompressed, as described above):

       +------+----------------------+
       | Type | Legacy, Uncompressed |
    +--+------+----------------------+-------------+
    | Address | 1Bu6YxH64nfvhdDsYNEP8PftoBMqgusdPS |
+---+---------+------------------------------------+----------------+
| Private Key | 5HqrbgkWPqBy6dvCE7FoUiMuiCfFPRdtRsyi6NuCM2np8qBZxq5 |
+-------------+-----------------------------------------------------+
       +------+--------------------+
       | Type | Legacy, Compressed |
    +--+------+--------------------+---------------+
    | Address | 18i5PtPisxbGiGGEviW7HPcnfNPmcsscwH |
+---+---------+------------------------------------+-----------------------+
| Private Key | p2pkh:KwLdv6T2jmhQbswnYrcL9KZHerTpVyjozp1JNjfP5QuD3GchCwCc |
+-------------+------------------------------------------------------------+
       +------+---------------+
       | Type | Native SegWit |
    +--+------+---------------+----------------------------+
    | Address | bc1q2jxe5azr6zmhk3258av7ul6cqtu4eu4mps8f4p |
+---+---------+--------------------------------------------+----------------+
| Private Key | p2wpkh:KwLdv6T2jmhQbswnYrcL9KZHerTpVyjozp1JNjfP5QuD3GchCwCc |
+-------------+-------------------------------------------------------------+