dexe-network / DeXe-Protocol

DeXe Protocol
https://dexe.network
20 stars 6 forks source link

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

Open Anas-debug opened 5 months ago

Anas-debug commented 5 months ago

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;

3. I added the following code to my `hardhat.config.js` file to specify the location of the `tasks` directory:
```javascript
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!

DangVanSo commented 2 months ago

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;