Scripts and Tasks
Automate workflows.
Scripts vs Tasks
Hardhat offers two ways to automate work:
- Scripts — plain Node.js files you run for one-off jobs like deployment.
- Tasks — reusable commands integrated into the Hardhat CLI with arguments and help text.
Use scripts for ad-hoc automation, tasks for repeatable commands your team reuses.
A Deployment Script
Scripts live in scripts/. A deploy script uses ethers from the Hardhat Runtime Environment:
const hre = require("hardhat");
async function main() {
const Greeter = await hre.ethers.getContractFactory("Greeter");
const greeter = await Greeter.deploy();
await greeter.waitForDeployment();
console.log("Deployed to:", await greeter.getAddress());
}
main();const hre = require("hardhat");
async function main() {
const Greeter = await hre.ethers.getContractFactory("Greeter");
const greeter = await Greeter.deploy();
await greeter.waitForDeployment();
console.log("Deployed to:", await greeter.getAddress());
}
main();All lessons in this course
- Hardhat Setup
- Compiling Contracts
- Scripts and Tasks
- Local Network and Forking