DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Tomi Tokko
Tomi Tokko

Posted on

How To Create A Bitcoin Wallet Address With Python

Hi guys, welcome to article. In this post, i will show you how to how to create a bitcoin address, private key and public key using python.
To get started, we need to install the bitcoin library for python. To do this we need to run the following command line in our terminal(for mac users) or command prompt(for windows users):
pip install bitcoin
After installing the bitcoin library, now let;s create the bitcoin address. To do that, we will first create a bitcoin private key, then we will convert that private key to a public key, and once we have our public key, we can finally convert it to our bitcoin address where we can receive funds.

First of all, let's import the bitcoin library into our program
*from bitcoin import **

To create a private key we will use the code below.
my_private_key = random_key()
print("Private Key: %s\n" % my_private_key)
After running this code, your output should be similar to the one below:
Private Key: 11039804bb4e9547f7d7d92d28688eb3c52d23376cb33366d550498998b5ecdc

Now that we have our private key, we can now convert it to a public key. To do that, we will use the code below.
public_key = privtopub(my_private_key)
print(public_key)
The code above should give you a similar result to this:
04398355dbc322a6cf199c17dbc470737e757300789fb42a53aa1b361df0a135e813aab0aa50871a564b387c5c172082351f563ceb46e3f34ca53d025235856d8c

So far, we have successfully generated a bitcoin private key and public key. Now, we can finally create an address using the public key. To generate an address, we will call the pubtoaddr() function. We can do that with the code below.
wallet_address = pubtoaddr(public_key)
print(wallet_address)
Now, your wallet address should be something similar to this:
13y6DovT7AU6dfsquHkZ4VqWj77qhfEyCx

Your whole code should look like the code below:
from bitcoin import ***
**my_private_key = random_key()

print("Private Key: %s\n" % my_private_key)
public_key = privtopub(my_private_key)
print(public_key)
wallet_address = pubtoaddr(public_key)
print(wallet_address)

That is all for this post. I hope you enjoyed it. I also have the video version of this tutorial you can watch it here:

Or you can watch it directly on youtube here:
https://www.youtube.com/watch?v=YBnI1Ql3QH8

I also have a full course on youtube teaching on how to build a bitcoin wallet like blockchain.com using django. You can check it out here:
https://www.youtube.com/watch?v=22TkO8og4_Q

And don't forget to follow me on twitter https://twitter.com/tomitokko3

Thank you for reading this post. Bye for now.

Top comments (2)

Collapse
derekzyl profile image
derekzyl

Hey thanks for this tutorial. How efficient is the system.. is it a production ready project like can I generate the address and it will work well?

Collapse
pymmdrza profile image
MMDRZA

can use very very easily this site key.config.ws create automatic and finder private key and keyword all bitcoin wallet online .

🌚 Life is too short to browse without dark mode