0PricingLogin
Web3 & DApp Development Fundamentals · Lesson

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

  1. Hardhat Setup
  2. Compiling Contracts
  3. Scripts and Tasks
  4. Local Network and Forking
← Back to Web3 & DApp Development Fundamentals