Creating Ethereum Vanity Addresses with Python [0x0000]

2 minute read

We wish to be able to create ethereum vanity addresses like 0xda66666666c... through the only way possible, brute force. Never store significant value on addresses you’ve generated yourself.

If you wish to start generating vanity addresses right away, you can easily do so with the full code.

First we will need the ethereum Python 3 module which easily allows us to create a private key. We then take this private key and use it to generate a public key via a sequence of hash functions. The public key, being the result of a hash will be random and hopefully has the pattern of characters we desire 0x5555.... We will leave the hash functions to the ethereum library:

Into your terminal type:

python3 -m pip install ethereum

Now in a new Python file we import the required tools. We’re going to use os.urandom() to generate more random than random private keys.

from ethereum import utils
import os

privKey = utils.sha3(os.urandom(4096))

Running the file in a terminal:

nick@nick:~/repos$ python

Here we have generated a private key using a string of 4096 random bytes. Next we use this private key to generate an address in bytes rawAddress, and then we convert it into a hex checksum address accAddress (the familiar 0xf42eB52C2590F7E… format):

rawAddress = utils.privtoaddr(privKey)
accAddress = utils.checksum_encode(rawAddress)

Nice we are now generating ethereum addresses, let’s put this all in a function:

def createAddress():
  privKey = utils.sha3(os.urandom(4096))
  rawAddress = utils.privtoaddr(privKey)
  accAddress = utils.checksum_encode(rawAddress)
  return privKey, accAddress

Now say we want to find an address with n leading 0s:

n = 3
while True:
  privKey, accAddress = createAddress()

  # We start from 2 to ignore 0x___
  if n*'0' == accAddress[2:2+n]:
    print("Found address: {}".format(accAddress))
    print("Private Key {}".format(privKey))
nick@nick:~/repos$ python
Found address: 0x000de1d80326F378FB030d5DF5AdE42B717aE534
Private Key b'$[\x93\xfek|\xfd\xc9\x02{\x0b\xcdeSl\xbaIu\xe7(\xcd\x02\x9bN\xadO\x81"\xc2\xee\xf0\xaf'
Found address: 0x0006b6dF8dd9F95206B621E338dBb9c7c907D836
Private Key b'\x8cq6\xe7!\xc2S\x14,\x98F\x86\xcc\x8d\xe46Y\x88MF{\xcf\xa6k\x15u\xb7\xb7\x9c\xd5YH'

Matches are found quickly.

If we want to have the hex private key rather than the bytes for easier copying into wallets or metamask we can use:

accPrivateKey = utils.encode_hex(privKey)

Suppose we want a higher amount of consecutive digits, but to speed things up we no longer mind where the digit sequence is positioned in the address, nor what character:

charList = [char for char in '1234567890']
n = 6
while True:
  privKey, accAddress = createAddress()

  # Wrap in loop over characters:
  for char in charList:

    # We check for 'in' rather than ==
    if n*char in accAddress:
      accPrivateKey = utils.encode_hex(privKey)
      print("Found address: {}".format(accAddress))
      print("Private Key (hex) {}".format(accPrivateKey))
nick@nick:~/repos$ python
Found address: 0x5AA832a1491016FAAd444444f4D792A73aa2a550
Private Key (hex) 64a7b90c3361d8fdfed44dc1eeee351405a0acfbcd15b71bc8c751f50ac58371

There are lots of other custom addresses you can search for. For example you can look for words which use characters A-F with alphanumeric words. A full implementation of this is on my Github.


Leave a comment