Deterministic Deployment
Deterministic Deployment Proxy Contracts on IoTeX:
What is Deterministic Deployment
"Deterministic deployment" refers to a technique used in various blockchain projects where the same bytecode can be deployed on different blockchains to produce the same contract address. This is achieved through the following two steps:
Deploy the "Proxy Contract"
Replay a special transaction on the target blockchain to deploy a "proxy contract."
The sender of this transaction must be a new address on the target blockchain, i.e., with a nonce of 0.
This will result in the creation of a specific address for the proxy contract.
Deploy the Desired Contract
Use the proxy contract to deploy the desired bytecode.
Inside the proxy contract, the CREATE2 opcode is used to create contracts, so the final contract address depends only on the hash of the bytecode, being independent of the nonce.
This ensures deterministic contract addresses on any blockchain.
Proxy Contract Example
This is a popular repository for a deterministic deployer used by many projects:
The test.sh
script performs 2 main steps:
Deploy the proxy
It deploys the proxy ("deployer") contract first, which will get the contract address
0x4e59b44847b379578588920ca78fbf26c0b4956c
.
Deterministically Deploy a Contract
It calls the proxy contract to deploy a demo contract, which will always get the same address regardless of when and where it's deployed (as long as it's created by calling the given proxy and with the same bytecode).
Deterministic Deployment on IoTeX
On IoTeX, the project above has been used to deploy a publicly accessible proxy contract for deterministic deployment, whose address is 0x4e59b44847b379578588920ca78fbf26c0b4956c
, same for both testnet and mainnet.
Last updated