Crypto glossary

CREATE2 and counterfactual addresses

Definition

CREATE2 is an EVM opcode that deploys contracts to an address computed in advance, so an address can be used before the contract behind it even exists.

With the original CREATE opcode, a new contract's address depends on the deployer and its transaction count, which is hard to predict. CREATE2, added in the Constantinople upgrade of 2019 through EIP-1014, derives the address from the deployer, a chosen salt and the hash of the contract's creation code. Anyone who knows those inputs can calculate the address beforehand, which is called a counterfactual address.

This underpins much of modern wallet design. Smart accounts can show users an address to receive funds immediately and only deploy the contract when the first transaction is sent, saving gas. Factories use it to deploy the same contract to the same address on many chains, and protocols such as decentralised exchanges use it to locate pool addresses without storing a lookup table.

Counterfactual addresses come with traps. Funds sent to an address on a chain where the contract was never deployed may be unrecoverable, or claimable by whoever deploys there first if the factory allows it, a scenario behind a known 2022 loss of tokens on Optimism. Matching addresses across chains does not guarantee matching code or owners.

Example

A new smart wallet shows the user a receiving address straight away; the account contract is only deployed, via CREATE2, when the user makes their first payment.

Related terms

Latest articles on CREATE2 and counterfactual addresses