Initializable.sol (2024)

The Solidity based Immutable Ecosystem

View on GitHub

View Source: @openzeppelin\contracts-upgradeable\proxy\utils\Initializable.sol

↘ Derived Contracts: ActivateToken, ContextUpgradeable, CreatorToken, CustomToken, ERC165Upgradeable, ERC20Upgradeable, ERC721BurnableUpgradeable, ERC721EnumerableUpgradeable, ERC721Upgradeable, ERC721URIStorageUpgradeable, ImmutableEntity, ImmutableProduct, OwnableUpgradeable, ProductActivate, StringCommon

Initializable

This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed behind a proxy. Since proxied contracts do not make use of a constructor, it’s common to move constructor logic to an external initializer function, usually called initialize. It then becomes necessary to protect this initializer function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. The initialization functions use a version number. Once a version number is used, it is consumed and cannot be reused. This mechanism prevents re-execution of each “step” but allows the creation of new initialization steps in case an upgrade adds a module that needs to be initialized. For example: [.hljs-theme-light.nopadding]

 contract MyToken is ERC20Upgradeable { function initialize() initializer public { __ERC20_init("MyToken", "MTK"); } } contract MyTokenV2 is MyToken, ERC20PermitUpgradeable { function initializeV2() reinitializer(2) public { __ERC20Permit_init("MyToken"); } }

TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as possible by providing the encoded function call as the _data argument to {ERC1967Proxy-constructor}. CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. [CAUTION] ==== Avoid leaving a contract uninitialized. An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke the {_disableInitializers} function in the constructor to automatically lock it when it is deployed: [.hljs-theme-light.nopadding]

 ///## Contract Members**Constants & Variables**```jsuint8 private _initialized;bool private _initializing;

Events

event Initialized(uint8 version);

Modifiers

  • initializer
  • reinitializer
  • onlyInitializing

initializer

A modifier that defines a protected initializer function that can be invoked at most once. In its scope, onlyInitializing functions can be used to initialize parent contracts. Equivalent to reinitializer(1).

modifier initializer() internal

Arguments

| Name | Type | Description || ————- |————- | —–|

reinitializer

A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the contract hasn’t been initialized to a greater version before. In its scope, onlyInitializing functions can be used to initialize parent contracts. initializer is equivalent to reinitializer(1), so a reinitializer may be used after the original initialization step. This is essential to configure modules that are added through upgrades and that require initialization. Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in a contract, executing them in the right order is up to the developer or operator.

modifier reinitializer(uint8 version) internal

Arguments

Name Type Description
version uint8

onlyInitializing

Modifier to protect an initialization function so that it can only be invoked by functions with the {initializer} and {reinitializer} modifiers, directly or indirectly.

modifier onlyInitializing() internal

Arguments

| Name | Type | Description || ————- |————- | —–|

Functions

  • _disableInitializers()
  • _setInitializedVersion(uint8 version)

_disableInitializers

Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call. Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized to any version. It is recommended to use this to lock implementation contracts that are designed to be called through proxies.

function _disableInitializers() internal nonpayable

Arguments

| Name | Type | Description || ————- |————- | —–|

_setInitializedVersion

function _setInitializedVersion(uint8 version) private nonpayablereturns(bool)

Arguments

Name Type Description
version uint8

Contracts

Initializable.sol (2024)

FAQs

What is initializable? ›

That can be initialized.

How to use _disableInitializers? ›

The _disableInitializers() function

The implementation contracts themselves are never upgraded, only the proxy. So setting the version to type(uint64). max (_initialized in the implementation) ensures the implementation contract will never be initialized.

What are upgradeable contracts? ›

Upgradeable smart contracts are a pattern composed of THREE contracts: Proxy contract: The smart contract the user interacts with directly. This contracts holds the contract state (ie, the important data is held here!). This is an EIP1967 standard proxy contract.

How do I update OpenZeppelin? ›

Upgrading using the Upgrades Plugins
  1. Deploy the implementation contract (our Box contract)
  2. Deploy the ProxyAdmin contract (the admin for our proxy).
  3. Deploy the proxy contract and run any initializer function.

Is initializable a word? ›

The resulting word initializable is a derivative word. In short, if something can be initialized, it is initializeable.

What does initialize payment mean? ›

Initializes citizen payment information for processing by a third party payment system that will send and commit final payment information into Automation.

What is an example of a proxy contract? ›

A proxy agreement is a contract between two parties that gives one the legal right to make decisions on behalf of the other under certain circ*mstances. An example of a proxy agreement would be when a shareholder allows a designated third party to make votes on their behalf.

How does the beacon proxy work? ›

The beacon proxy pattern allows the creation of multiple proxies for one implementation, with the ability to upgrade them all at once. The factory deploys new proxies, which use delegatecall to an address retrieved from the beacon. The beacon serves as the source of truth for the implementation.

What are the 4 types of contracts? ›

10 Different Types of Contracts
Type of ContractEveryday Use
Implied ContractsCommon in everyday transactions like dining out.
Express ContractsStandard in formal business agreements.
Simple ContractsUsed for straightforward services or transactions.
Unconscionable ContractsOften challenged in court for fairness.
10 more rows
Jul 18, 2024

Does an upgrade mean a new contract? ›

An upgrade is when you choose to renew your existing mobile contract with the same network provider. If you choose to switch network the industry classes this as a new connection.

What are the 4 real contracts? ›

Justinian's law recognizes as real contracts the following: mutuum (loan); commodatum (loan for use - service), depositum (deposit) and pignus (pledge).

Can a smart contract be modified? ›

Smart contracts are immutable, meaning that once they are deployed on the blockchain, they cannot be changed or deleted. This ensures that they are tamper-proof and reliable, but also limits their flexibility and adaptability.

What is OpenZeppelin? ›

OpenZeppelin provides a great platform for creating smart contracts in a secure manner. It offers reusable and thoroughly tested code that has been audited. Similar to using someone else's code, you can modify it to suit your requirements.

What are smart contracts in blockchain? ›

What are smart contracts? Smart contracts are digital contracts stored on a blockchain that are automatically executed when predetermined terms and conditions are met.

What does it mean to initialize something? ›

: to set (something, such as a computer program counter) to a starting position, value, or configuration. initialization.

What is the initializable method in JavaFX? ›

In JavaFX, the initialize() method is like a special helper that gets called when you start your program. It's used to set things up in your computer program, especially for the things you see on the screen, like buttons or lists. You don't need to call this initialize() yourself; the computer does it for you.

What does initializing device mean? ›

Device initialization is doing whatever steps are required to bring a device into a working state. It has got little to do with variable initialization. The process is specific for every device, there are no magic values that would initialize any device that you come across.

What is auto initialization? ›

Auto initialization occurs when you define a class variable ie static variable. there are default values for each data type.

Top Articles
Self-Made Billionaire: There Are Three Levels Of Reality, And Most People Are Stuck In Level One, But They Have No Idea - Michael D. Simmons
KeePass CVE-2023-32784: Detection of Processes Memory Dump
Xre-02022
Friskies Tender And Crunchy Recall
Comcast Xfinity Outage in Kipton, Ohio
How To Get Free Credits On Smartjailmail
Delectable Birthday Dyes
Category: Star Wars: Galaxy of Heroes | EA Forums
Www Thechristhospital Billpay
How Many Cc's Is A 96 Cubic Inch Engine
Trini Sandwich Crossword Clue
180 Best Persuasive Essay Topics Ideas For Students in 2024
Letter F Logos - 178+ Best Letter F Logo Ideas. Free Letter F Logo Maker. | 99designs
Leader Times Obituaries Liberal Ks
Does Breckie Hill Have An Only Fans – Repeat Replay
Harem In Another World F95
Nail Salon Goodman Plaza
Voy Boards Miss America
List of all the Castle's Secret Stars - Super Mario 64 Guide - IGN
Fraction Button On Ti-84 Plus Ce
Lcwc 911 Live Incident List Live Status
Copart Atlanta South Ga
V-Pay: Sicherheit, Kosten und Alternativen - BankingGeek
Wisconsin Volleyball Team Boobs Uncensored
Construction Management Jumpstart 3Rd Edition Pdf Free Download
Foolproof Module 6 Test Answers
Koninklijk Theater Tuschinski
Used Patio Furniture - Craigslist
Telegram Voyeur
How do you get noble pursuit?
Sandals Travel Agent Login
Harrison 911 Cad Log
Nurofen 400mg Tabletten (24 stuks) | De Online Drogist
Stouffville Tribune (Stouffville, ON), March 27, 1947, p. 1
Gus Floribama Shore Drugs
Pfcu Chestnut Street
Boneyard Barbers
Pnc Bank Routing Number Cincinnati
Gideon Nicole Riddley Read Online Free
Atlantic Broadband Email Login Pronto
Jennifer Reimold Ex Husband Scott Porter
Wattengel Funeral Home Meadow Drive
Smith And Wesson Nra Instructor Discount
Timberwolves Point Guard History
Firestone Batteries Prices
Senior Houses For Sale Near Me
Chubbs Canton Il
From Grindr to Scruff: The best dating apps for gay, bi, and queer men in 2024
Adams-Buggs Funeral Services Obituaries
Meee Ruh
Latest Posts
Article information

Author: Nathanial Hackett

Last Updated:

Views: 6610

Rating: 4.1 / 5 (52 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Nathanial Hackett

Birthday: 1997-10-09

Address: Apt. 935 264 Abshire Canyon, South Nerissachester, NM 01800

Phone: +9752624861224

Job: Forward Technology Assistant

Hobby: Listening to music, Shopping, Vacation, Baton twirling, Flower arranging, Blacksmithing, Do it yourself

Introduction: My name is Nathanial Hackett, I am a lovely, curious, smiling, lively, thoughtful, courageous, lively person who loves writing and wants to share my knowledge and understanding with you.