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.
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.
The JS deploy()
function accepts N required params, followed by 1 optional:
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.