Generate your Own Vanity Addresses for Ethereum and Bitcoin in Python

in #bitcoin6 years ago (edited)

opengraph.png

Hello!

Today, we're going to be writing a really simple python script to generate vanity addresses, which are cryptocurrency addresses that start with a certain phrase or sequence of letters. The process involves generating private keys and checking the address for the address phrase until you find a satisfactory one.

Packages

First, we're going to need to install some packages that can perform the calculations for generating valid public addresses from a private key. For generating bitcoin addresses, you need to go to the terminal and type

pip install bitcoin

For generating ethereum addresses, you will need to install ethereum by typing

pip install ethereum

Code

The code is quite simple, you just have to create a while loop that constantly generates addresses, checking them against your target phrase. Here's the code for bitcoin addresses:

from bitcoin import *

target = input('Input Target Phrase\n>')

priv = random_key()
addr = pubtoaddr(privtopub(priv))

while not addr.lower().startswith('1{}'.format(target)):
    priv = random_key()
    addr = pubtoaddr(privtopub(priv))

print('Address: {}\nPrivate Key: {}'.format(addr, priv))

Ethereum is a little different because it doesn't have a built in random key generator, so you have to import os to generate random numbers and use SHA3 to hash them to generate a private key.

Also, be aware that ethereum addresses are in hexadecimal, which only uses the cahracters a-f and 0-9, so you are limited in the types of addresses you can generate. If you input a target that is not in hexadecimal, it will loop indefinitely because it will never generate an address containing non-hexadecimal characters.

from ethereum import utils
import os

target = input('Input Target Phrase\n>')

priv = utils.sha3(os.urandom(4096))
addr = utils.checksum_encode(utils.privtoaddr(priv))

while not addr.lower().startswith('0x{}'.format(target)):
    priv = utils.sha3(os.urandom(4096))
    addr = utils.checksum_encode(utils.privtoaddr(priv))

print('Address: {}\nPrivate Key: {}'.format(addr, priv.hex()))

I hope you have some fun with these! Also, be aware that each additional character in the target phrase increases the generation difficulty exponentially, so don't go too long. Upvote below if you enjoyed!

Sort:  

Congratulations @kachangred! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of upvotes

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

Upvote this notification to help all Steemit users. Learn why here!