How to install Hardhat on Ubuntu

How to install Hardhat on Ubuntu

Hardhat is a development environment that facilitates building on Ethereum. It helps developers manage and automate the recurring tasks that are inherent to the process of building smart contracts and DApps, as well as easily introducing more functionality around this workflow. This means compiling and testing at the very core.

Hardhat also comes built-in with Hardhat Network, a local Ethereum network designed for development. It allows you to deploy your contracts, run your tests and debug your code.

Most Ethereum libraries and tools are written in JavaScript, and so is Hardhat. If you're not familiar with Node.js, it's a JavaScript runtime built on Chrome's V8 JavaScript engine. It's the most popular solution to run JavaScript outside of a web browser and Hardhat is built on top of it.

To install and use Hardhat, you must have nodeJs installed.

Installing Node.js on Ubuntu

You can skip this section if you already have a working Node.js. If not, here's how to install it on Ubuntu.

  • Open a new terminal

WhatsApp Image 2022-03-31 at 10.34.48 PM.jpeg

  • Copy and paste these commands one after the other into your terminal:

sudo apt update

sudo apt install curl git

curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -

sudo apt install nodejs

Installing Hardhat on Ubuntu

We'll install Hardhat using the npm CLI. The Node.js package manager is a package manager and an online repository for JavaScript code.

  • Open a new terminal WhatsApp Image 2022-03-31 at 10.34.48 PM.jpeg
  • Make a new directory using the command mkdir seun-nfts

  • Open your new directory using this command cd seun-nfts

  • Generate an empty npm project using npm init -y

  • install hardhat using npm install --save-dev hardhat

WhatsApp Image 2022-03-31 at 10.46.41 PM.jpeg you should see the same display as the screenshot above in your terminal

You may see a message about vulnerabilities after you run the last command and install Hardhat. Do not fret as nobody is hacking your pc.

If you are at this stage, you should have successfully installed Hardhat

Now let us get our project running

  • On your terminal input this command npx hardhat

  • Choose the option to create a basic sample project. Say yes to everything.

  • Then run npx hardhat run scripts/sample-script.js

You should see something like this WhatsApp Image 2022-03-31 at 10.52.24 PM.jpeg

Congratulations, you have successfully installed Hardhat and you are ready to write your first smart contract.