How we can set PublicKey semi-random?

Hi, I wonder how people set ‘meaingful’ publickey like below

TOKEN_PROGRAM_ID : it starts with ‘Token’, so that easy to see that it is TOKEN_PROGRAM_ID
‘TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA’

Serum coin mint addres : it starts with SRM, which is symbol of serum coin
‘SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt’,

How is it possible?

Hi @gil_mon and welcome to the forum! :wave:

You can use the solana-keygen grind command, which will literally randomly generate tons and tons of keypairs, until it finds one that happens to start with the letters you are looking for. It can take days to find a matching keypair depending on how powerful your computer is and how many letters you want it to look for, whether or not you care about the letters being uppercase/lowercase, etc.

If you wanted to find 1 key that started with GiL for instance you could run:

solana-keygen grind  --starts-with GiL:1
Searching with 12 threads for:
	1 pubkey that starts with 'GiL' and ends with ''
Wrote keypair to GiLWutLvChrKnbPMBKtBdNFAX79fazfJoWpMo28mEmQ1.json

You can also have it generate a key with a valid seed phrase too, though it will take even longer:

solana-keygen grind  --use-mnemonic --starts-with GiL:1
Searching with 12 threads for:
	1 pubkey that starts with 'GiL' and ends with ''

For added security, enter a BIP39 passphrase

NOTE! This passphrase improves security of the recovery seed phrase NOT the
keypair file itself, which is stored as insecure plain text

BIP39 Passphrase (empty for none): 

Wrote keypair to GiL5DKUazhvVPUCcXkprPmYwZ8f3JztjhmwNuk3eRvUP.json
=============================================================================
Found matching key GiL5DKUazhvVPUCcXkprPmYwZ8f3JztjhmwNuk3eRvUP

Save this seed phrase and your BIP39 passphrase to recover your new keypair:
west limit genre kingdom arrive enact million transfer filter tenant visa joy
=============================================================================
2 Likes

Wow. This is dope. Thank you so much!

1 Like