How can I call ERC2771ContextUpgradeable's constructor?

How can I set the trustedforwarder address in ERC2771ContextUpgradable contract?

:1234: Code to reproduce

contract Wallet is Initializable, ERC2771ContextUpgradeable, UUPSUpgradeable {

    function initialize(address _operator, address _trustedForwarder) 
            public 
            initializer
        {
            OPERATOR = _operator;
            trustedForwarder = _trustedForwarder;
        }

    function _msgSender() internal view override(ERC2771ContextUpgradeable) returns (address sender) {
        sender = ERC2771ContextUpgradeable._msgSender();
    }

    function _msgData() internal view virtual override(ERC2771ContextUpgradeable) returns (bytes calldata) {
        return ERC2771ContextUpgradeable._msgData();
    }

}

:computer: Environment

ERC2771ContextUpgradeable uses a constructor to set an immutable variable (see reasoning in this PR). So you would need a constructor in your implementation to invoke ERC2771ContextUpgradeable's constructor. (You should still use an initializer for everything else though).

1 Like