Skip to content

Hardhat does not recognize deploy task in tasks/deploy.js file #190

@Anas-debug

Description

@Anas-debug

I am trying to deploy a contract using Hardhat, but I am encountering an "Error HH303: Unrecognized task 'deploy'" issue. Here are the steps I have taken:

  1. I created a new Hardhat project using npx hardhat.
  2. I created a deploy.js file in the tasks directory with the following code:
const { ethers } = require("hardhat");

async function deploy() {
  const [deployer] = await ethers.getSigners();
  const MaliciousContract = await ethers.getContractFactory("contracts/malicious_contracts/MaliciousContract");
  const maliciousContract = await MaliciousContract.deploy();
  await maliciousContract.deployed();
  console.log("MaliciousContract deployed to:", maliciousContract.address);
}

module.exports = deploy;
  1. I added the following code to my hardhat.config.js file to specify the location of the tasks directory:
module.exports = {
  paths: {
    tasks: "./tasks",
  },
  // other config options...
};
  1. I ran the command npx hardhat --network localhost deploy to deploy the contract.

Expected Result:
The MaliciousContract contract should be deployed to the local blockchain network and its address should be logged to the console.

Actual Result:
I received the following error message:

Error HH303: Unrecognized task 'deploy'

For more info go to https://hardhat.org/HH303 or run Hardhat with --show-stack-traces

I have tried specifying the full path to the deploy.js file in my command (npx hardhat --network localhost tasks/deploy.js), but I received the same error message. I have also tried running Hardhat with the --debug flag, but I did not see any additional information that would help me identify the issue.

I am using Hardhat version 2.9.3 and Node.js version 14.17.3.

Please let me know if there is any additional information I can provide to help diagnose this issue. Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions