deployProxy bug? Error: Invalid number of parameters for "initialize". Got 5 expected 2! Only happens with deployProxy

Hey guys,

I'm trying to build a contract where users need to send LINK token to a contract before requesting a random number from the contract, using Chainlink's VRF. My contract is based on this post: https://stackoverflow.com/questions/67853438/smart-contracts-chainlink-vrf-openzeppelin-truffle-upgrades-compatibility.

This uses OpenZeppelin's Initializable abstraction, found here: https://github.com/OpenZeppelin/openzeppelin-contracts-
upgradeable/blob/master/contracts/proxy/utils/Initializable.sol.

This is what my contract's initialize function looks like:

function initialize(
    bytes32 _s_keyHash,
    uint256 _s_fee,
    address _vrfCoordinator,
    address _link
  ) public initializer {
    // VRF initializers
    VRFConsumerBaseUpgradable.initialize(_vrfCoordinator, _link);
    s_keyHash = _s_keyHash;
    s_fee = _s_fee;
    vrfCoordinator = _vrfCoordinator;
    link = _link;
    linkToken = LinkTokenInterface(_link);
  }

And this is what the initialize function of the contract it inherits from (VRFConsumerBaseUpgradeable) looks like:

function initialize(address _vrfCoordinator, address _link) public {
    vrfCoordinator = _vrfCoordinator;
    LINK = LinkTokenInterface(_link);
  }

And this is what my truffle migration file looks like, which tries to deploy the Blackjack contract:

module.exports = async function (deployer) {
  await deployProxy(
    Blackjack,
    [
      1000,
      "0x2ed0feb3e7fd2022120aa84fab1945545a9f2ffc9076fd6156fa96eaff4c1311",
      web3.utils.toWei("0.1", "ether"),
      "0xb3dCcb4Cf7a26f6cf6B120Cf5A73875B7BBc655B",
      "0x01BE23585060835E02B77ef475b0Cc51aA1e0709",
    ],
    { deployer }
  );
};

Which gives me the error in the title: Error: Invalid number of parameters for "initialize". Got 5 expected 2!.

Interestingly, this happens only when I use deployProxy, and does not error out when I use the regular deployer.Deploy(...), which makes me suspect this is a bug with deployProxy.

I tried Googling this with no luck. Anyone have an idea how I can solve this?

Any help is greatly appreciated, thank you in advance!

Hey,

It appears that the initialize function of your contract receives four arguments:

function initialize(
    bytes32 _s_keyHash,
    uint256 _s_fee,
    address _vrfCoordinator,
    address _link
  ) public initializer {}

However, when you deploy the contract using deployProxy, you appear to supply it 5 arguments:

deployProxy(
    Blackjack,
    [
      1000, (ARG 1)
      "0x2ed0feb3e7fd2022120aa84fab1945545a9f2ffc9076fd6156fa96eaff4c1311", (ARG 2)
      web3.utils.toWei("0.1", "ether"), (ARG 3)
      "0xb3dCcb4Cf7a26f6cf6B120Cf5A73875B7BBc655B", (ARG 4)
      "0x01BE23585060835E02B77ef475b0Cc51aA1e0709", (ARG 5)
    ],
    { deployer }
  );

The extra fifth argument is causing the issue.

1 Like