**
The language programming language these modifiers are crucial to ensuring that the contract is behaved as expected during its initialization phase.
What are initializer
Ionly modifiers "
?
Initializer andSelfitialization” are used to determine the conditions under which a function can be called. The primary difference between the two is when they are launched:
Initializer ': In other words, it is performed during the initialization phase.
- Samoinitializing
: Initialization, not on the following calls.
Correct use ofinitializerI
only a modifier modifier in inheritance to multiple levels
Inherits cases, where the contract inherits from another contract, it is crucial to use these modifiers correctly to avoid any potential problems. Here are some key points to consider:
Initialization sequence
When used inheritance to multiple levels, the sequence of initialization must be carefully controlled to ensure that the correct order of the call is mainly. The initializer" modifier "can be used at the highest contract level to invite his constructor.
Strength
Pragma Solidity ^0.8.0;
Multilelilinhecexample Treaty {
// upper level initializer
__init function () internal initiator {{
demand (msg.sener == "contract", "only contract");
Iche
// Underwriting 1
Sub -s -replies1 Structure structure
Private value address;
Public counter;
Iche
The Sub -Exalting Agreement is Multilevinhecexample {
Underwriting1 Public subcontracting;
Constructor () external initializer {{
Underwriting = New Podmontract1 ("Value", 0);
Iche
Iche
// Underwriting 2
SUB -TUPLI2 STRUCTURE STRUCTURE2
Private value address;
Public counter;
Iche
The contract under the report2 is Multileveliminhelimarcexample {
Under the interlocutor2 public subcontracting;
Constructor () external initializer {{
Underwriting = New Podmontract2 ("Value", 0);
Iche
Iche
Iche
Subgovac1will be carried out by transgressions', ensuring that it is only called once during initialization.
multiple callers
(E.g.,selfitializing), behavior can become unpredictable. To avoid such questions:
“ Strength
Pragma Solidity ^0.8.0;
Multilelilinhecexample Treaty {
// upper level initializer
__init function () internal initiator {{
Require (MSG.