Using Vanity Address
When optimizing gas usage in Ethereum smart contracts, every byte counts. One often overlooked optimization technique involves the use of vanity addresses and the CREATE2
opcode. This approach can lead to gas savings, especially when contract addresses are frequently used as function arguments.
Ethereum charges 4
gas for a zero byte of calldata and 16
gas for a non-zero byte. This pricing model applies both during normal function calls and contract deployment. As a result, addresses with more leading zeros can lead to gas savings when used as function arguments.
Key Points:
- Vanity addresses with leading zeros save calldata gas cost.
- Savings occur when the address is used as a function argument, not when calling the address directly.
- This principle applies to both contract addresses and EOAs (Externally Owned Accounts).
Example:
OpenSea's Seaport contract uses a vanity address: 0x00000000000000ADc04C56Bf30aC9d3c0aAF14dC
Using CREATE2 for Vanity Contract Address
The CREATE2 opcode allows for deterministic contract address generation. By carefully choosing the salt value, we can create contract addresses with desired patterns, such as leading zeros.