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, 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:Tolk
VanityStorage, checks whether the message comes from this owner, then loads DeployPayload and replaces the contract’s code and data with the cells from the incoming message.
In a vanity contract, a salt is a 256-bit value stored in StateInit along with five padding bits and the owner address. The contract declares this layout in VanityStorage, but only the owner field is needed at runtime. The salt does not affect runtime behavior and only influences the resulting address via the StateInit hash.
The owner field is required because someone could intercept an external message, extract the salt, and deploy their own contract with the same salt concurrently. Since the owner value also unpredictably affects the address, the intercepted salt is useless unless the attacker can send the message from the same owner address.
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 applies the provided code and data when deployed.
Generate salt
To generate thesalt, copy the code from src/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.
salt. It also writes found salt to the found.txt file. The search continues until it is stopped or exits after the first match when --only-one is set.
Example output
salt is found, it can be used to deploy an arbitrary smart contract at that address.
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:
TypeScript
scripts/deployExampleContract.ts:
TypeScript
<OWNER_ADDR>– address allowed to deploy via the vanity contract.<SALT_HEX>– 32-bytesaltin 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.