2

When I use Hardhat to deploy the contract in Sepolia, I keep getting the following error:

enter image description here

My deploy script:

const { ethers } = require("hardhat");

async function main() {
  const whitelistContract = await ethers.getContractFactory("Whitelist");
  const deployedWhitelistContract = await whitelistContract.deploy(10);
  await deployedWhitelistContract.deployed();
  console.log("Whitelist Contract Address:", deployedWhitelistContract.address);
}

main()
  .then(() => process.exit(0))
  .catch((error) => {
    console.error(error);
    process.exit(1);
  });

My hardhat-config file:

require("@nomicfoundation/hardhat-toolbox");
require("dotenv").config({ path: ".env" });

const QUICKNODE_HTTP_URL = process.env.QUICKNODE_HTTP_URL;
const PRIVATE_KEY = process.env.PRIVATE_KEY;

module.exports = {
  solidity: "0.8.10",
  networks: {
    hardhat: {},
    sepolia: {
      url: QUICKNODE_HTTP_URL,
      accounts: [`0x${PRIVATE_KEY}`],
   },
  },
};

3 Answers 3

2

Remove 0x from the private key. Just pass the private key like this

accounts: [process.env.PRIVATE_KEY]
3
  • I deployed without 0x and happened the same error: "TypeError: no matching function"
    – Duccini
    Jun 10, 2023 at 16:33
  • This is true if the private key already has the 0x prefix in the .env file
    – Rohan Nero
    Oct 26, 2023 at 21:50
  • @RohanNero Not in my case, I've never prefixed it with 0x, neither in the .env nor in the config. Not sure what's the case LOL Oct 27, 2023 at 5:09
2

The error message shows, .deployed() does not exist. so use waitForDeployment() instead .deployed().

and also use .target or await deployedWhitelistContract.getAddress() instead of .address

RIGHT CODE:

const { ethers } = require("hardhat");

async function main() {
  const whitelistContract = await ethers.getContractFactory("Whitelist");
  const deployedWhitelistContract = await whitelistContract.deploy(10);
  await deployedWhitelistContract.waitForDeployment();
  console.log("Whitelist Contract Address:", await deployedWhitelistContract.getAddress());
}

main()
  .then(() => process.exit(0))
  .catch((error) => {
    console.error(error);
    process.exit(1);
  });
0

Hardhat-tools changed the deployment's function syntax. For hardhat-tools 3.0.0 deploy() is now deployContract() and deployed() is now awaitForDeployment()

You can either downgrade your hardhat-tools version or use the new syntax.

1
  • This answer was taken directly from the OP's question body to better fit the Q and A format
    – Rohan Nero
    Oct 26, 2023 at 21:51

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.