0
0
Blockchain / Solidityprogramming~30 mins

Hardhat deployment scripts in Blockchain / Solidity - Mini Project: Build & Apply

Choose your learning style9 modes available
Hardhat Deployment Scripts
📖 Scenario: You are building a simple Ethereum smart contract deployment project using Hardhat. Hardhat is a tool that helps developers deploy smart contracts to Ethereum networks easily.In this project, you will create a deployment script step-by-step to deploy a basic smart contract called SimpleStorage that stores a number.
🎯 Goal: Build a Hardhat deployment script that deploys the SimpleStorage contract to a local Ethereum network.
📋 What You'll Learn
Create a deployment script file named deploy.js inside the scripts folder.
Use Hardhat Runtime Environment (hre) to deploy the contract.
Deploy the SimpleStorage contract and wait for deployment to finish.
Print the deployed contract address to the console.
💡 Why This Matters
🌍 Real World
Deploying smart contracts is a key step in launching blockchain applications like tokens, games, or finance apps.
💼 Career
Blockchain developers must write deployment scripts to automate contract deployment and testing in professional projects.
Progress0 / 4 steps
1
Create the deployment script file and import Hardhat
Create a file named deploy.js inside the scripts folder. Inside it, write const hre = require("hardhat"); to import Hardhat Runtime Environment.
Blockchain / Solidity
Need a hint?

Use require("hardhat") to import Hardhat Runtime Environment as hre.

2
Write an async function to deploy the SimpleStorage contract
Write an async function named main. Inside it, get the contract factory for SimpleStorage using hre.ethers.getContractFactory("SimpleStorage") and store it in a variable called SimpleStorage. Then deploy the contract by calling SimpleStorage.deploy() and store the deployed contract in a variable called simpleStorage. Use await to wait for deployment to finish by calling simpleStorage.deployed().
Blockchain / Solidity
Need a hint?

Use hre.ethers.getContractFactory to get the contract factory, then deploy and wait for deployment.

3
Call the main function and handle errors
After the main function, call it and add .then(() => process.exit(0)) to exit successfully. Add .catch((error) => { console.error(error); process.exit(1); }) to catch and print errors and exit with failure.
Blockchain / Solidity
Need a hint?

Use main().then(...).catch(...) to run the async function and handle errors.

4
Print the deployed contract address
Inside the main function, after await simpleStorage.deployed(), add a console.log statement to print "SimpleStorage deployed to:" followed by simpleStorage.address.
Blockchain / Solidity
Need a hint?

Use console.log("SimpleStorage deployed to:", simpleStorage.address) to print the address.