How to choose a contract or wallet address
Have you ever desired to customize the deployment address or the wallet address from where you're operating?
There is an easy way and it's thanks to Foundry and all the contributors.
The Profanity Hack in 2022 rekted lot of peoples who generated vanity addresses from a similar tool.
The randomness used in Foundry is pure randomness based on the system used.
As long as it should be safe to use, always be careful with those.
The base command is
cast wallet new
It will generate a new wallet address and a new private key.
You can customize the address with the following flags:
--starts-with X
Replace X with numbers from 0 to 9 and letters from a to f.
To also customize the end of the address you can use:
--ends-with X
For example
>>cast wallet vanity --starts-with aa --ends-with bb
Starting to generate vanity address...
Successfully found vanity address in 0 seconds.
Address: 0xaa23Fb120E826C40eE59CAba6a01c06b219dB9bB
Private Key: 0xa1fcf3876dc7908978cc78a04d81234dd23d9446182cb3d1462431b31ed8b81a
will generate an address that starts with "aa" and ends with "bb".
You can do the same with contract address!
In this case, a new parameter is needed
--nonce X
Replace X with the nonce number you need to use to deploy that contract.
Let's say for example i generate this one
>>cast wallet vanity --starts-with aa --ends-with bb --nonce 1
Starting to generate vanity address...
Successfully found vanity address in 0 seconds.
Contract address: 0xaAEbD2Caf38821100980D29Ea62cDA45cf0eddBB
Address: 0x4f562a7F8059713880379FE51A30dE783b97f69C
Private Key: 0x5d759a7917e0c4544472fa8ea3ae4ecefc03b1b3372b6623461a85f8231bc8df
I need to deploy a contract with nonce 1, so i need to do one transaction before deploying the contract.