I have a problem deploying my contract

This error is displayed when I want to deploy my contract:
PS C:\Users\D-W\Desktop\hardhat2> npx hardhat run scripts/deploy.js
Error: too many arguments: in Contract constructor (count=2, expectedCount=0, code=UNEXPECTED_ARGUMENT, version=contracts/5.7.0)
at Logger.makeError (C:\Users\D-W\Desktop\hardhat2\node_modules@ethersproject\logger\src.ts\index.ts:269:28)
at Logger.throwError (C:\Users\D-W\Desktop\hardhat2\node_modules@ethersproject\logger\src.ts\index.ts:281:20)
at Logger.checkArgumentCount (C:\Users\D-W\Desktop\hardhat2\node_modules@ethersproject\logger\src.ts\index.ts:347:18)
at ContractFactory. (C:\Users\D-W\Desktop\hardhat2\node_modules@ethersproject\contracts\src.ts\index.ts:1237:16)
at step (C:\Users\D-W\Desktop\hardhat2\node_modules@ethersproject\contracts\lib\index.js:48:23)
at Object.next (C:\Users\D-W\Desktop\hardhat2\node_modules@ethersproject\contracts\lib\index.js:29:53)
at C:\Users\D-W\Desktop\hardhat2\node_modules@ethersproject\contracts\lib\index.js:23:71
at new Promise ()
at __awaiter (C:\Users\D-W\Desktop\hardhat2\node_modules@ethersproject\contracts\lib\index.js:19:12)
at ContractFactory.deploy (C:\Users\D-W\Desktop\hardhat2\node_modules@ethersproject\contracts\lib\index.js:1138:16) {
reason: 'too many arguments: in Contract constructor',
code: 'UNEXPECTED_ARGUMENT',
count: 2,
expectedCount: 0
}

this is my deploy.js :

const hre = require("hardhat");

async function main() {
  const currentTimestampInSeconds = Math.round(Date.now() / 1000);
  const unlockTime = currentTimestampInSeconds + 60;

  const lockedAmount = hre.ethers.utils.parseEther("0.001");

  const Token = await hre.ethers.getContractFactory("erfan");
  const token = await Token.deploy(unlockTime, { value: lockedAmount });

  await token.deployed();

  console.log(
    `token deployed to ${lock.address}`
  );
}

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

what's problem?

This error-message tells you that you are passing 2 input arguments instead of 0.

And indeed, you are passing 2 input arguments:

The 2nd argument is { value: lockedAmount }.
Hardhat knows how to pass it as the transaction's ETH value instead of a regular function argument.

But that still leaves 1 redundant argument, namely unlockTime, which you should avoid passing.

1 Like