Constructor Arguments in deployProxy() Function of Transparent Proxy Pattern

Hi there,
I am using hardhat-upgrades library to write functionality of transparent proxy upgrades. I have no initialize function in my base contract. I want to call constructor with 2 parameters.
From BoxV1 and BoxV2 example, tutorial passes [42] value in second parameter of deployProxy() function. I want to know how can I pass 2 string parameters to the contract constructor in deployProxy() function.
I have tried passing array of 2 strings, simple 2 strings, an object of 2 strings but every time I get the same error:
The error is as follows:

Error: types/values length mismatch (count={"types":2,"values":0}, value={"types":[{"name":"name","type":"string","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"string","_isParamType":true},{"name":"symbol","type":"string","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"string","_isParamType":true}],"values":}, code=INVALID_ARGUMENT, version=abi/5.5.0)

Anyone please help me in this regard!
Thanks

Hi @abdullah, generally your implementation contract should use an initializer instead of a constructor if you will be using a proxy. For a detailed explanation, see https://docs.openzeppelin.com/upgrades-plugins/1.x/proxies#the-constructor-caveat

The second parameter for the deployProxy() function should be an array representing the arguments for the initializer (not the constructor).

Thank You for your reply @ericglau. This was helpful

Yes, generally, but then you have cases like this

Now I'm trying to figure out the same thing as OP, what do you have to pass into deployProxy to get this to work?

const MyContract = await hre.ethers.getContractFactory("MyContract");
myContract = await hre.upgrades.deployProxy(MyContract, [forwarderAddress]);
await myContract.deployed();

The above just gives me the following error:

Error: types/values length mismatch (count={"types":1,"values":0}, value={"types":[{"name":"forwarder","type":"address","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"address","_isParamType":true}],"values":[]}, code=INVALID_ARGUMENT, version=abi/5.7.0)

This is the contract code:

contract MyContract is
    Initializable,
    ERC2771ContextUpgradeable
{
 
    /// @custom:oz-upgrades-unsafe-allow constructor
    constructor(address forwarder)
        ERC2771ContextUpgradeable(forwarder)
    {}

    function initialize(string memory _tokenURI) public initializer {
        _setTokenUri(0, _tokenURI);
    }
}

I reached a dead-end here

See https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable/pull/155#issuecomment-1330816863

1 Like