Blog

Initialization of proxy contracts with modifier functions.

Since proxy contracts do not use constructors, initialization logic that would typically go into a constructor must be moved to an external function. This contract helps developers define such initialization functions that can only be called once, preventing multiple initializations of a contract.


initializer Modifier

The initializer modifier ensures that a contract’s initialization logic can only be executed once. Without this protection, the contract could be re-initialized multiple times and most likely get exploited (depending on the logic). The modifier tracks whether the contract has already been initialized and emits an Initialized event after the first successful initialization.

reinitializer Modifier

The reinitializer modifier is used for upgradeable contracts that may require additional initialization steps during future upgrades. It allows a function to be executed only if the contract hasn’t been initialized to a higher version yet. Each version can only be initialized once, ensuring that the contract maintains its integrity.