체인의정석

Contract `` has a constructor Define an initializer instead 본문

블록체인/Solidity

Contract `` has a constructor Define an initializer instead

체인의정석 2023. 2. 28. 10:10
728x90
반응형

https://forum.openzeppelin.com/t/security-advisory-initialize-uups-implementation-contracts/15301/23

 

Security advisory: Initialize UUPS implementation contracts

Thank you @frangio I have upgraded the OpenZeppelin Upgradeable Contracts to version 4.3.2. I am using the following in my Smart Contract, and do not have any Constructor in my Contract itself: contract MyContract is Initializable, ERC721Upgradeable, Ownab

forum.openzeppelin.com

 

업그레이더블 컨트렉트에서는 initializer만 있어야 하고 constructor는 없어야 한다.=

하지만 initializer를 쓰더라도 이를 이용해 다시 접근할 수 있기 때문에

import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";


     constructor() {
        _disableInitializers();
    }

만약 initializer를 다시 한번 쓰려는 의도가 없다면 constructor에서 _disableInitializers를 쓰는게 좋다.

이 때 constructor를 넣고 싶다면

    /// @custom:oz-upgrades-unsafe-allow constructor

이런 문구를 위에 써주어야 오류가 나지 않는다.

728x90
반응형
Comments