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

Could you please take a look at this github issue where I've attempted to do exactly what you've prescribed?

I'm wondering how this would affect the functionality of @openzeppelin/hardhat-upgrades considering that it does complain when you try to deployProxy on a contract that uses a constructor. I'm also wondering how one would use upgradeProxy as well if a constructor is indeed present in the contract.

@idiocracy Responded in the issue to use the constructorArgs option with the Upgrades Plugins.

1 Like