Matrix AI Network Utils — Part 2: Generating a Vanity Address(JS, NodeJS), Beginner level
by Delbypoc
This tutorial is for educational purposes only, I’m not responsible for any losses, damages, or other liabilities which may occur by using any info/code provided here(or anywhere else it is posted).
I’m under no circumstances a Javascript professional (or a JS Ninja/Expert)!
The code is not production ready! (only for learning purposes)
In this guide, I’m going to show you how to generate an vanity MAN address (Mainnet).
To keep it simple, for this program we will make use of the ETH to MAN address convertor we displayed in the last article:
We will make use of the following packages : ‘crypto’, ‘ethereumjs-util’, ‘buffer’, ‘polycrc’, ‘bs58’.
You can install them by using :
npm install ethereumjs-util buffer polycrc bs58
Let’s start programming!
First off, we are going to start by generating a random wallet, we are going to call this function ’generateRandomWallet’:
Then we will make a function that verifies if the wallet we provide contains the word we choose (the parameter in the function is called ‘input’), we will call this function ‘addressContainsTheInput’:
Then we will make a function that generates a random wallet until it finds one that contains the input (addressContainsTheInput returns true), we will name it ‘generateVanityWallet’:
For example, if we want an address that contains the word ‘Enjoy’:
Note: The time it takes to find an address depends on your computer specs (and a bit of luck), it took me around 10 seconds to generate an address that contains the word `enjoy`, longer sequences takes more time.
Note: This is not an efficient program, there are better ways to generate a vanity address (especially if you make use of GPU-s core count or CPU multi-threading)
Sample output:
{
publicAddress: ‘MAN.2ZyEnjoy2tk5yPB2YrziUVTQAFWAV’,
privateKey:
‘c17b95305a3d0ad80a4ca4020ab7850cf5e75557b273dbbce625cd5f8c95f286’
}
Whole program (https://github.com/CognitiveProcessing/Matrix-AI-Network-Code-Snippets/blob/main/js/generateVanityAddress.js)
For more documentation on the packages used, you can check:
https://www.npmjs.com/package/bs58
https://www.npmjs.com/package/buffer
https://www.npmjs.com/package/polycrc
https://www.npmjs.com/package/ethereumjs-util
https://nodejs.org/api/crypto.html
Also, check out the official Matrix AI Network Developer Portal: