0

I want to be able to switch between which account calls the function by passing the name as the parameter to the task:

yarn hardhat doSomething --name deployer --network localhost

task(
    "doSomething",
    "calls doSomething on most recent Foobar contract"
)
    .addParam("name", "your account name from the namedAccount config")
    .setAction(async ( namedAccount) => {
        console.log("grabbing and connecting namedAccount to contract...")
        const foobar = await ethers.getContract(
            "Foobar", namedAccount
        )
        console.log("Success!")
        await tokenWizardAuto.doSomething()
}

However this returns: Error: invalid signer or provider

1 Answer 1

1

You could indicate the position of the account to be used as a parameter and store an array of accounts in an env file. Like:

task(
    "doSomething",
    "calls doSomething on most recent Foobar contract"
)
    .addParam("index", "your account name from the namedAccount config")
    .setAction(async ( namedAccount) => {
const MNEMONICS: string = process.env.MNEMONICS!;
const accounts: string[] = MNEMONICS.split(",");
const account =hre.ethers.Wallet.fromMnemonic(accounts[taskArgs.index]);

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.