1

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

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

2 Answers 2

2

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.

1

The arguments are given inside the script. The line you showed only executes the script and does little else - all the actual deployment logic is inside the script itself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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