Skip to content

Feature request: --reset flag for hardhat deploy task #592

Description

@technophile-04

Hello! We're currently migrating scaffold-eth-2 from hardhat 2 + hardhat-deploy v1 to hardhat 3 + hardhat-deploy v2 at scaffold-eth/scaffold-eth-2#1272

In v1, we had yarn deploy --reset which would force a redeploy even if the contract bytecode hadn't changed. This was useful during local development when you want a fresh contract instance on the same running chain (clean state, new address) without restarting the node.

In v2, the deploy task doesn't have a --reset flag. The alwaysOverride option on env.deploy() does the right thing at the API level, but there's no way to trigger it from the CLI.

What we're doing now:

We added a --reset flag via overrideTask("deploy") that sets an env var, and wrapped the deploy extension in rocketh/config.ts to read that env var and pass alwaysOverride: true:

// hardhat.config.ts
overrideTask("deploy")
  .addFlag({ name: "reset", description: "Force re-deploy" })
  .setInlineAction(async (args, _hre, runSuper) => {
    if (args.reset) {
      process.env.HARDHAT_DEPLOY_RESET = "true";
    }
    await runSuper(args);
  })
  .build();

// rocketh/config.ts
const deployWithReset = ((env: any) => {
  const deployFn = deployExtension.deploy(env);
  return (name: any, args: any, options?: any) => {
    const isReset = process.env.HARDHAT_DEPLOY_RESET === "true";
    return deployFn(name, args, { ...options, alwaysOverride: isReset || options?.alwaysOverride });
  };
}) as typeof deployExtension.deploy;

This works but the wrapper loses type safety (we have to cast through any because the deploy function is generic). Would be cleaner if the deploy task supported --reset natively, either by passing alwaysOverride through to all deploy scripts, or by clearing the deployment files before executing.

For context, the v1 --reset had issues (#300 , #130 ) around deleting all deployments when used with --tags. The alwaysOverride approach is actually better since it works per-contract, but it just needs a CLI entry point.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions