Must a child contract use the namespaced storage pattern


In v5 the upgradable contracts are using the namespace storage pattern as defined in ERC7201. Do the contracts which import these upgradable contracts need to use this pattern or can the state variables be defined as usual?

Thank you

:1234: Code to reproduce

For example in this child contract MyContract we are importing v5 contracts but defining the state variables like exampleNumber, exampleMapping, exampleString in a normal way.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";

contract MyContract is Initializable, OwnableUpgradeable, UUPSUpgradeable {

    uint256 exampleNumber;
    mapping (uint256 key => uint256 value) exampleMapping;
    string exampleString;

    /// @custom:oz-upgrades-unsafe-allow constructor
    constructor() {

    function initialize(address initialOwner) initializer public {

    function _authorizeUpgrade(address newImplementation)

:computer: Environment

Remix, Any

Child contracts can use state variables and/or namespaced storage. Just note that if you use state variables, the state variables in your contracts won't have the benefits of namespaced storage and those benefits will only apply to the v5 contracts that you import.

1 Like