My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more
What is hardhat and how to deploy your first smart contract using it?

What is hardhat and how to deploy your first smart contract using it?

Anish Jain's photo
Anish Jain
·Mar 2, 2022·

1 min read

Here is everything you need to know

hardhat is a toolkit that helps you to create, deploy, test, and run your smart contract.

Setup

Install yarn

npm install -g yarn

yarn init -y

yarn add -D hardhat

Create your hardhat project

npx hardhat

Click Yes for everything.

Project Structure

Screenshot from 2022-03-02 12-00-29.png

let's go to the contract folder and write your smart contract code

raycast-untitled (6).png

Create a deploy script inside the scripts folder

raycast-untitled (5).png

Now open 2 new instances of your terminal and

In one of them run

npx hardhat node

This kicks off the local blockchain pretty dope yep

In 2nd

// This compiles your contracts 
npx hardhat compile

// This 'll deploy 
npx hardhat run scripts/deploy --network localhost

Save the deployed Contract address

How to interact with your Smart contract from the terminal console

npx hardhat console --network localhost

const a = await ethers.getContractFactory('NFTee')
const b = await a.attach('YOUR_DEPLOY_CONTRACT_ADDRESS')

await b.getName()
// Output: Anish