-1

So I have written the same code as the hardhat documentation suggest here for deploying with funding maybe.

import hre from "hardhat";

const main = async () => {
  const currentTimestampInSeconds = Math.round(Date.now() / 1000);
  const ONE_YEAR_IN_SECS = 365 * 24 * 60 * 60;
  const unlockTime = currentTimestampInSeconds + ONE_YEAR_IN_SECS;
  const lockedAmount = hre.ethers.utils.parseEther("1");

  const waveContractFactory = await hre.ethers.getContractFactory("WavePortal");
  const waveContract = await waveContractFactory.deploy(unlockTime,
    { value: lockedAmount }
  );
  await waveContract.deployed();
  console.log("Contract deployed to:", waveContract.address);
}

but the problem is it will give me an error about the argument. enter image description here

even if it's the same code that the documentation suggest here: https://hardhat.org/hardhat-runner/docs/guides/deploying.

First I have written code in a different manner from buildspace website as a part of learning about web3.

// from buildspace website
const main = async () => {
  const waveContractFactory = await hre.ethers.getContractFactory("WavePortal");
  const waveContract = await waveContractFactory.deploy({
    value: hre.ethers.utils.parseEther("0.001"),
  });

  await waveContract.deployed();

  console.log("WavePortal address: ", waveContract.address);
};

This above code from buildspace but the problem is it will also give the error and I thought it could be the old deprecated code so I look into docs.

TylerH
  • 20,799
  • 66
  • 75
  • 101
Visrut
  • 360
  • 4
  • 14

1 Answers1

1

The JS deploy() function accepts N required params, followed by 1 optional:

  • N arguments of the Solidity constructor
  • 1 optional object that overrides default params of the deploying transaction (in your case the value)

Based on the error message "Expected 0-1 arguments", the WavePortal constructor expects 0 params. Which makes the deploy() function to expect 0 constructor params, plus the 1 optional overriding object.

However your code is trying to pass unlockTime as the constructor param.

Solution: Remove the unlockTime from the JS code - or accept it in the Solidity code.

Petr Hejda
  • 40,554
  • 8
  • 72
  • 100
  • 1
    I have to make the contract's constructor `payable` which was not specified in `hardhat docs` unfortunately because they were talking in the context of `Lock.sol` contract. Thanks for your answer, I understood deploy method actually depends upon the solidity contract. – Visrut Jan 03 '23 at 05:32