StateInit depend on constant data that is randomly generated many times until a desired address is found. It is often used to deploy contracts with a specific prefix or suffix so the address is visible in block explorers.
The contract code and data are included in the vanity deploy message. The vanity contract is first deployed with a StateInit that produces the desired address (see Addresses overview), and then immediately sets its actual state from the payload. This is a special case of upgrading contract’s code.
Prerequisites
How it works
The vanity contract code:owner field is required, because someone might intercept an external message, find salt in it, and concurrently deploy their own contract with this salt. Because a value of the owner field changes the address in an unpredictable way, an intercepted salt will be useless, unless attacker can send the message from the same owner address.
The 256-bit salt is stored in this contract’s StateInit in addition to five padding bits and the owner address. The salt is not used by the contract’s logic (it is skipped with ds~skip_bits(256);); it only influences the resulting address via the StateInit hash.
Because a contract address is derived from the StateInit hash, changing the salt changes the address deterministically. The search for a suitable salt happens entirely off-chain: a Python script (with an OpenCL kernel for speed) generates many random salt values, computes the resulting address, and reports matches. The on-chain vanity contract does not brute-force salts; it only verifies the owner and then sets the provided code and data when deployed.
Generate salt
To generate the salt, copy the code fromsrc/generator in the same repository. It includes the run.py script and the vanity.cl OpenCL kernel.
Run the command with the desired search parameters, including -w for the workchain and the owner address allowed to perform the deployment. The example below searches on the basechain for the specified suffix.
<SUFFIX>— desired address suffix; case sensitive when--case-sensitiveis set.<OWNER_ADDR>— address allowed to deploy via the vanity contract.
found.txt file. The search continues until it is stopped or exits after the first match when --only-one is set. Example output:
Deploy the contract
Deploy of the vanity contract and the message that replaces its code and data usually come in a single message:wrappers/VanityContract.ts:
scripts/deployExampleContract.ts:
<OWNER_ADDR>— address allowed to deploy via the vanity contract.<SALT_HEX>— 32-byte salt in hex found by the generator.
npx blueprint run. The deployment succeeds when <OWNER_ADDR> matches the address of the wallet used for actual deployment. ExampleContract can be replaced with any contract; the vanity contract does not depend on the specifics of the code or data.