[Ethereum] How to pass constructor argument with hardhat

hardhat

How to pass constructor argument with hardhat? Is it something like this:

npx hardhat run scripts/deploy.js --network rinkeby --constructor args?

Best Answer

You've to add constructor arguments inside your deployment script.,

For eg.,

const hre = require("hardhat");
const ethers = hre.ethers;

async function main() {
    const Greeter = await ethers.getContractFactory("Greeter");
    const greeter = await Greeter.deploy("Hello World")
    await greeter.deployed();
    console.log("Contract deployed to:", greeter.address);
}
  
main()
.then(() => process.exit(0))
.catch(error => {
    console.error(error);
    process.exit(1);
});

For verification on etherscan using cli,

npx hardhat run scripts/deploy.js --network rinkeby --constructor-args arguments/greeter.arguments.js

where inside a folder called arguments, a file named greeter.arguments.js we will have the arguments to our deployed contract.

Related Topic