This tutorial will show how to build a very basic Brain Wallet with Python. A Brain Wallet is a phrase that is created by the user the that user links to the seed of a crypto wallet. So in order to access the crypto wallet ,the users must type in the phrase exactly. The wallet can be used to store any type of crypto currency. The thing is, you must not for get the brain wallet phrase! If you forget or miss spell the phrase you will not be able to access the wallet. Once the phrase is forgotten the currency will be lost forever.
Before getting started with the code, the python library bitcoin must be imported. This library is really useful if you want to use python to interact or create bitcoin block chain structures.
First, we must create a Private key and choose a phrase for the brain wallet. This can be done by using the built in functions from the library. So for this example, the phrase is ” Never forget you’r Brain Wallet Phrase! ” . Note that privtopub() is used to turn the private key to a public key.
from bitcoin import *
#Creating the Phrase
Private_Key = sha256("Never forget your Brain Wallet Phrase!")
toPublic_Key = privtopub(Private_Key)
Lastly, a bitcoin address must be given to the phrase so it can interact with the block chain. Note that if you were to miss spell or leave out a character or symbol to the phrase it will Not be excepted because the hash of the Phrase will be different.
#Setting the Bitcoin Address
Create_Adress = pubtoaddr(toPublic_Key)
print("Your Brain Wallet :" ,Create_Adress)
Output :
Your Brain Wallet : 1KHtp1E9mQUG1b5DDzd2TmTLAqX7t8JZuT
There it is, the phrase has be turned in to a hash code and given a bitcoin address. So key take away would be Brain wallets are cool but kinda impractical unless your trying to flee the country and they are suspect to being hacked into so if you are gonna create a brain wallet make sure to use a randomly generated phrase because it can be cracked if it is a weak phrase. Also its probably best to create a more advanced brain wallet than the one above if you plan on using actually it . Feel free to play around with the code, the full code is posted below.
from bitcoin import *
#Creating the Phrase
Private_Key = sha256("Never forget your Brain Wallet Phrase!")
toPublic_Key = privtopub(Private_Key)
#Setting the Bitcoin Address
Create_Adress = pubtoaddr(toPublic_Key)
print("Your Brain Wallet :" ,Create_Adress)