Stellar blockchain quickly became my favourite one because of its lightness, versatility and ease of use. Other than exchange Lumen, the native coin (XLM), with Stellar it is possible to create our own tokens, use the built-in marketplace, create smart contracts and so on. On public, testing or even private blockchain.

As a big fan of the command line and Python, it is very simple for me to issue any sort of operations and transactions on Stellar directly from my keyboard.

Surely, Stellar Laboratory is a great tool to interact with Stellar blockchain. But coders will be having more fun writing some lines of code, in order to accomplish more complex tasks at the speed of light. Fortunately, interaction with Stellar Horizon is very well supported for different programming languages, including Python. Take a look at py-stellar-base, a damn simple and useful Python library.

I’m going to post more code about Stellar with Python very soon. Meantime, in this post, I want to show you how to search for vanity wallet addresses - in other words, addresses containing a given string of characters or reflecting particular logical properties. Just using some Python code.

I’ve been inspired in doing so by Lumenaut1 - and this is another story! Take a look at the address of the donation wallet in this page: cool! Isn’t it? Check it out here.

So I tried by myself to search for a valid address containing my name. To find a sequence of five characters in any position didn’t take too much (some minutes)2 with my i7 laptop Linux computer. Here is the code (Python3, download from Github - of course, you must install the above mentioned py-stellar-base package before).

from stellar_base.keypair import Keypair

def save_keypair(address, seed):
    with open('vanity_wallets.txt', 'a') as f:
        f.write('{}\n{}\n\n'.format(address, seed))

while True:
    keypair = Keypair.random()
    a = keypair.address().decode()
    if 'FABIO' in a:
        save_keypair(a, keypair.seed().decode())
        print('FOUND! {}'.format(a))

Set your favourite condition at line 10. For example, find wallets having the same character in the last five positions:

    if a[-1] == a[-2] == a[-3] == a[-4] == a[-5]:

Please note that required time may explode exponentially as the complexity of the conditions increases.

For any found wallet, public address is printed out on the screen and the corresponding keypair (public address + secret seed) is appended in the local file (vanity_wallets.txt).

As you already know, secret seeds are the passwords for the corresponding public addresses, so you must not share them with others and must keep them in a safe place! Especially if you are going to use some of those newly generated wallets.

Have you chosen your brand new vanity wallet? Well, create it on the blockchain by putting some Lumen in it - or ask for some XLM to Friendbot if you’re working on the testnet. To do so, Stellar Laboratory is still your friend and we will see how to proceed in some other posts here.

But before going on, let’s do a last check on a keypair: is the secret seed valid for our new wallet? Check it from command line (download code):

from stellar_base.keypair import Keypair
from sys import argv

if len(argv) < 3:
    print('Usage: verify_keypair.py <ADDRESS> <SECRET>')
    exit()

try:
    k = Keypair.from_seed(argv[2])
except Exception as e:
    print(str(e))
    exit()

print('keypair verification: {}'.format('OK' if str(k.address().decode()) == argv[1] else 'FAIL'))

And we are done. I wrote this post in the hope that you enjoy Stellar blockchain too.


  1. I’ve set Lumenaut as inflation destination for all my wallets. Please vote for these guys! ↩︎

  2. Need more speed? Take a look at Stellar Go SDK↩︎