Hardhat
Deploying Smart Contract Using Hardhat
In this article, we'll learn how to build a smart contract with Hardhat.
Preparation
Before you start, make sure that the following prerequisites are installed.
Node.js and npm
Hardhat
Project Setting
Create a new directory for your project and navigate to it.
Run the following command to initialize a new npm project.
Run the following command to install Hardhat.
Run the following command and follow the prompts to initialize Hardhat.
Writing Smart Contract
In the
contracts
directory, create a solidity file named MyContract.sol.Create a file as shown below.
Deploying Smart Contract
Create a new file called
deploy.js
in thescripts
directory.Write a deployment script using Hardhat's deployment API.
Run the following command to run the deployment script.
Set the network name to deploy to.
This script deploys a smart contract and writes the contract address to the console.
Wrapping Up
You've successfully deployed a smart contract using Hardhat. Now you can call the deployed contract using its address.
For more information, visit Hardhat's official website.