0

I got this error when I tried to deploy my contract: deployScriptfunc is not a function

this my code:

  const hre = require("hardhat");

  async function main() {
      console.log("deploying flashtoken!!");

      const flashtoken = await hre.ethers.getContractFactory("Flashtoken");
      const Flashtoken = await flashtoken.deploy();
      await Flashtoken.deployed();

      console.log(`deployed flashtoken at ${Flashtoken.address}`);

      console.log("deploying swapp!!");

      const swapp = await hre.ethers.getContractFactory("Swapp");
      const Swapp = await swapp.deploy(Flashtoken.address);
      await Swapp.deployed();

      console.log(`deployed swapp at ${Swapp.address}`);
  }

  main().catch((error) => {
      console.error(error);
      process.exitCode = 1;
  });
3
  • how did you run hardhat to deploy and compile it
    – haxerl
    Oct 23, 2022 at 4:26
  • yarn hardhat deploy Oct 23, 2022 at 14:36
  • I added the hardhat deploy plugin Oct 23, 2022 at 14:37

3 Answers 3

1

If you're using the hardhat-deploy plugin, then you only have to write a deploy function and then export it from the file and not call and execute it.

This is one of the ways you might want to do this:-

  const hre = require("hardhat");

  const main = async function () {
      console.log("deploying flashtoken!!");

      const flashtoken = await hre.ethers.getContractFactory("Flashtoken");
      const Flashtoken = await flashtoken.deploy();
      await Flashtoken.deployed();

      console.log(`deployed flashtoken at ${Flashtoken.address}`);

      console.log("deploying swapp!!");

      const swapp = await hre.ethers.getContractFactory("Swapp");
      const Swapp = await swapp.deploy(Flashtoken.address);
      await Swapp.deployed();

      console.log(`deployed swapp at ${Swapp.address}`);
  }
  module.exports = main;

Also you needn't even give a name to this function because it is redundant in this context and you can do write this deploy script this way too.

  const hre = require("hardhat");

  module.exports = async function main() {
      console.log("deploying flashtoken!!");

      const flashtoken = await hre.ethers.getContractFactory("Flashtoken");
      const Flashtoken = await flashtoken.deploy();
      await Flashtoken.deployed();

      console.log(`deployed flashtoken at ${Flashtoken.address}`);

      console.log("deploying swapp!!");

      const swapp = await hre.ethers.getContractFactory("Swapp");
      const Swapp = await swapp.deploy(Flashtoken.address);
      await Swapp.deployed();

      console.log(`deployed swapp at ${Swapp.address}`);
  }
1
  • This worked but this was an temporary fix i got this error when running npx hardhat node what i did was use this while running the command then called main() when running the script worked like a charm Dec 5, 2023 at 5:06
0

I got the problem because is used "yarn hardhat deploy" instead of "yarn hardhat run scripts/deploy.js" and i also deleted the hardhat deploy plugin

0

The error TypeError: deployScript.func is not a function typically occurs when you are trying to call a function that doesn't exist. In the code you provided, the error is not related to the deployment script itself. It seems to be a generic error message that might be thrown by the deployment tool or another part of your code.

Based on the code snippet you provided, there doesn't seem to be an obvious cause for this error. The deployment script appears to be straightforward and should work correctly as long as the contracts "Flashtoken" and "Swapp" are defined properly in your project

OR

Check the folder directory of your contract, there should be a file called tempCodeRunnerFile.js, if there is, Just delete it. the error should go away

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.