1

I'm preparing the task that allows to grant role to addresses from list.

const { task } = require("hardhat/config");

task("add_addresses")
  .addParam("rolesControl")
  .addParam("addressesArray")
  .setAction(async (taskArgs, hre) => {
    const rolesContract = await hre.ethers.getContractAt(
      "RolesControl",
      taskArgs.rolescontrol
    );
    await rolesContract.markParticipants(taskArgs.addressesArray);

  });

module.exports = {};

I tried to pass the arguments like this

npx hardhat add_addresses --network rinkeby --rolescontrol "0xAed7E176616C834a3eF300601D284E95C4302fEf" --addressesArray ["random address"]

And received error :

Error: invalid value for array (argument="value", value="[0x9d34859383eA75acE0D9415447A47805c62Ba91e]", code=INVALID_ARGUMENT, version=contracts/5.6.2) 

Need help to figure out how to pass args correctly

1 Answer 1

2

This should work:

task("add_addresses")
    .addParam("rolesControl")
    .addVariadicPositionalParam("addressesArray")
    .setAction(async (taskArgs, hre) => {
        console.log(taskArgs)
    })


npx hardhat add_addresses --roles-control 0xAed7E176616C834a3eF300601D284E95C4302fEf address1 address2 address3

taskArgs.addressesArray will be an array: ["address1", "address2", "address3"]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.