3

When trying to deploy my smart contract, I get this error message:

TypeError: no matching function (argument="key", value="deployed", code=INVALID_ARGUMENT, version=6.5.1)

at main (C:\Users...\simple-storage\backend\scripts\deploy.js:16:26) at processTicksAndRejections (node:internal/process/task_queues:95:5) { code: > 'INVALID_ARGUMENT', argument: 'key', value: 'deployed' }

I'm using hardhat for deploying with this deploy.js code:

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

async function main() {
  const simpleStorageContract = await ethers.getContractFactory(
    "SimpleStorage"
  );

  const deployedContract = await simpleStorageContract.deploy("Hello World!");

  await deployedContract.deployed(); // error is here

  console.log("SimpleStorage Contract Address:", deployedContract.address);
}

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

Anyone have any idea what might be causing this?

4 Answers 4

5

This is due to the changes in hardhat-tools 3.0.0. Make the following changes deploy => deployContract, deployed => waitForDeployment

So your main function would look like -

async function main() {
  const deployedContract = await ethers.deployContract("SimpleStorage",["Hello World"]);

  await deployedContract.waitForDeployment();

  console.log("SimpleStorage Contract Address:", await deployedContract.getAddress());
}
3
  • Thank you. SimpleStorage is the name of the contract. Where do I include "Hello world", which is the string input of the constructor? Jun 11, 2023 at 4:49
  • Inputs to constructor can be provided as the second parameter of deployContract in the form of an array, I have edited the answer to include this. Jun 12, 2023 at 5:52
  • I started using hardhat 2.16.0 and hardhat tools 3, so the last line of code to get address should be changed to: await deployedContract.target Jul 8, 2023 at 4:57
1
const deployedContract = await hre.ethers.deployContract("Hello World!");
await deployedContract.waitForDeployment(); 
console.log("SimpleStorage Contract Address:", deployedContract.target);

Replace your code with above one, It will work without any errors.

1
  • SimpleStorage is the name of the contract. Where do I include that? Hello world is just the string input of the constructor. Jun 11, 2023 at 4:48
0

Yes, I was able to solve it by installing the earlier version of hardhat. (I didn't try Alwin's answer/code yet with the new version3.0.0 of hardhat; their answer might work instead of downgrading the version, like I'm suggesting.)

instead of: npm install --save-dev hardhat

do: npm install --save-dev --save-exact [email protected]


instead of: npm install --save-dev @nomicfoundation/hardhat-toolbox

do: npm install --save-dev @nomicfoundation/hardhat-toolbox2

0

I have the following script in my deploy.js: const hre = require("hardhat");

const main = async () => {
  const transactionsFactory = await hre.ethers.deployContract("Transactions");

  await transactionsFactory.waitForDeployment();

  console.log("Transactions address: ", transactionsFactory.getAddress());
  console.log("Transactions address: ", transactionsFactory.address);
  console.log("Transactions address: ", transactionsFactory.target);
  console.log("Hello World!");
};

const runMain = async () => {
  try {
    await main();
    process.exit(0);
  } catch (error) {
    console.error(error);
    process.exit(1);
  }
};

runMain();

When I run npx hardhat run scripts/deploy.js --network goerli I see Compiled 1 Solidity file successfully in the terminal, but no other messages which I expected from the console.log statement. Now I am not sure if the contract was deployed successfully or not. Why is console.log not showing in the terminal? I am using VS Code Solidity extention by Juan Blanco, "hardhat": "^2.15.0" and "@nomicfoundation/hardhat-toolbox": "^3.0.0".

Not the answer you're looking for? Browse other questions tagged or ask your own question.