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)
The code above should give you a similar result to this:

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)
Now, your wallet address should be something similar to this:

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)
wallet_address = pubtoaddr(public_key)

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:

I also have a full course on youtube teaching on how to build a bitcoin wallet like using django. You can check it out here:

And don't forget to follow me on twitter

Thank you for reading this post. Bye for now.

Top comments (2)

derekzyl profile image

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?

pymmdrza profile image

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