I would like to test a contract in the hardhat console, but in order to do so I need to deploy a number of supporting contracts which includes several libraries, and I handle that inside a deploymenment script.

What Im wondering if I can do that inside the console (started without a --network parameter) so its running its own isolated node inside console. I'm already using my running local node for something else and it already contains test data which I'd rather not have to recreate.

I tried un scripts/myDeployScript.ts but that doesnt work in the console.

1 Answer 1


You can do it the same way you do into any .js files:

await run('myTask', {foo: "bar"})


If myTask is defined like this example:

task("myTask", "Prints the network name and a foo arg")
  .addOptionalParam("foo", "Will be printed if defined")
  .setAction(async ({foo}, { ethers, network }) => {

    console.log(` * network: ${network.name}`);
    if (foo) {
    console.log(` * foo: ${foo}`);

  return {
    network: network.name,
$ hh console --network localhost
Welcome to Node.js v14.xx.xx.
Type ".help" for more information.
> const res = await run('myTask', {foo: "bar"})
 * network: localhost
 * foo: bar
> res
{ foo: 'bar', network: 'localhost' }
  • Does it have to be a task? Can it be a script in your scripts directory?
    – GGizmos
    Apr 29, 2022 at 20:15

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.