Ethereum: What is the correct usage of `initializer` and `onlyInitializing` modifiers in case of multi-level inheritance in upgradeable contracts?

The role of “initial” and “only oninitializing” modifiers in updated contracts

When implementing agreements to be updated in the Ethereum solidity programming language, it is necessary to understand the proper use of two editors: initiator 'and' only oninitialization '. These editors are crucial to ensure that contract behavior was expected.

What are the "introduction" andonly oninitializing ‘modification?

In firmness, both the “substrate” and ‘only oninitialization’ are used for certain conditions where the function can be called. The primary difference between the two is when they are triggered:

  • “Treasurer”: This most edit is used to rely on a builder that has been completed or an external entity (eg, an agreement with automatic retention). In other words, it has completed the introduction phase.

  • Ainoalinitialization: This most edit is used to appeal to a function that must only be called when the contract is formatted. It ensures that the function is only called the duration of the duration and not to ALIGNAL calls.

“initiator” and “Only is the correct use of vaininitializing” modifiers in multi -level heritage

Ethereum: What is the correct usage of `initializer` and `onlyInitializing` modifiers in case of multi-level inheritance in upgradeable contracts?

In multi -level inheritance cases in which the agreement levies on another agreement, it is necessary to use the thesis editors to avoid any problems. Here are some key points for the consultant:

Introduction sequence

When using a multi -level heritage, it is carefully controlled by the introduction sequence to ensure that the correct call order is maintained. The “initial” modifier can be used at the highest level of the contract to calculate its builder.

`Severity

Pragman solidity ^0.8.0;

A contract of multi -level contract

// top -level initial

Function __init () Internal initiator {

Require (msg.sendender == "contracha", "only contract");

}

// subcontracting 1

Struct subcontract1 {

Point to private value;

UINT Public counter;

}

The subcontract of the contract1 is multi -level

Subcontracting1 Public subcontracting;

Constructor () External Introduction {

Subcontracting = new subcontract1 ("value", 0);

}

}

// down contract 2

Struct subcontract2 {

Point to private value;

UINT Public counter;

}

Contract agreement2 is multi -level

Subcontracting2 Public subcontracting;

Constructor () External Introduction {

Subcontracting = new subcontract2 ("value", 0);

}

}

}

In this example, “subcontract1” is performed before ‘subcontracting’, ensuring that it is only once called the duration of the duration.

several callers

If there are several callers for the same function on a different modifator (eg “singleinitialization), Bezavir may become unpredictable. To avoid such questions:

` Severity

Pragman solidity ^0.8.0;

A contract of multi -level contract

// top -level initial

Function __init () Internal initiator {

Demanding (msg.

پاسخ دهید

آدرس ایمیل شما منتشر نخواهد شد. فیلدهای الزامی هستند.