Hardhat Constructor – Passing an Array of Constructor Arguments Through hardhat-etherscan in CLI

cliconstructorhardhatjavascriptsolidity

Here is the code that I used to deploy this contract to the Rinkeby network.

const hre = require("hardhat");

async function main() {
  // Hardhat always runs the compile task when running scripts with its command
  // line interface.
  //
  // If this script is run directly using `node` you may want to call compile
  // manually to make sure everything is compiled
  // await hre.run('compile');

  // We get the contract to deploy
  const paySplit = await hre.ethers.getContractFactory("paySplit");
  const paysplit = await paySplit.deploy(["0x16DD346Aa1483264DBb0Dde64235081C867fb3f2", "0x6d6257976bd82720A63fb1022cC68B6eE7c1c2B0"], [35, 65]);

  await paysplit.deployed();

  console.log("paySplit deployed to:", paysplit.address);
}

main().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});

As you can see I pass my constructor arguments through the deploy function as so. I am used to just copy and pasting this in my npx hardhat verify command. When I run the command

npx hardhat verify --network rinkeby 0x0ed0074898c451E8379F6B1C763D5426beAcD511 (["0x16DD346Aa1483264DBb0Dde64235081C867fb3f2", "0x6d6257976bd82720A63fb1022cC68B6eE7c1c2B0"], [35, 65]

it gives me an error.

ParserError: Line | 1 | … network rinkeby 0x0ed0074898c451E8379F6B1C763D5426beAcD511 (["0x16DD3 … | ~ | Missing type name after '['.

It seems that there is something that I need to do to pass the the array containing my addresses. However, I have no idea what I should do. What can I do to pass these arrays in the hardhat command line?

Best Answer

I found out that you can actually create an arguments.js script that basically allows you to plugin the same arguments as you do in your deploy script. You just have to make sure to use the flag --constructor-args scripts/arguments.js

Here is the arguments.js script:

module.exports = [
    ["0x16DD346Aa1483264DBb0Dde64235081C867fb3f2", "0x6d6257976bd82720A63fb1022cC68B6eE7c1c2B0"], [35, 65]
]

Reference to docs

Related Topic