Solving the TypeError: no matching function Error in Hardhat

Solving the TypeError: no matching function Error in Hardhat

It's a bug-fix day. I encountered an error while attempting to deploy my contract to the testnet using Hardhat with the command below.

npx hardhat run scripts/deploy.js --network <testnet>

After spending a couple of hours debugging, I realized that I had followed a similar process to deploy the contract just last week, and it worked perfectly. However, it is no longer working now.

I figured this error was due to the changes/upgrades in @nomicfoundation/hardhat-toolbox to version 3.0.0 when you create a new hardhat project.

The old way of writing the deployment script that caused the error:

const hre = require("hardhat");

async function main() {
  const Contract = await hre.ethers.getContractFactory("Contract");
  const contract = await Contract.deploy(
    "<Your constructor argument here>"
  );

  await contract.deployed();

  console.log(`Contract deployed to ${contract.address}`);
}

main().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});

How to write the deployment script to fix the error:

const hre = require("hardhat");

async function main() {
  const Contract = await hre.ethers.deployContract("Contract", 
    ["<Your constructor argument here>"]
  );

  await Contract.waitForDeployment();

  console.log(`Contract deployed to ${await Contract.getAddress()}`);
}

main().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});

That's it 🥳🥳🥳

This post explained and fixed the error in deployment caused by the hardhat tools upgrade to version 3.0.0 when deploying a contract to testnet.

I'd love to connect with you on Twitter | LinkedIn | GitHub | Portfolio

See you in my next blog article. Take care!!!