Hardhat: Deploying a Smart Contract

Learn how to deploy a simple Solidity-based smart contract to Uptick using the Hardhat environment

Hardhat is a flexible development environment for building Ethereum-based smart contracts. It is designed with integrations and extensibility in mind

Pre-requisite Readings

Install Dependencies

Before proceeding, you need to install Node.js (we'll use v16.x) and the npm package manager. You can download directly from Node.js or in your terminal:

Ubuntu

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

sudo apt install -y nodejs

MacOS

# You can use homebrew (https://docs.brew.sh/Installation)
$ brew install node

# Or you can use nvm (https://github.com/nvm-sh/nvm)
$ nvm install node

You can verify that everything is installed correctly by querying the version for each package:

If you haven't already, you will also need to install Uptick if you plan on deploying your smart contracts locally. Check this document for the full instructions.

Create Hardhat Project

To create a new project, navigate to your project directory and run:

Following the prompts should create a new project structure in your directory. Consult the Hardhat config page for a list of configuration options to specify in hardhat.config.js. Most importantly, you should set the defaultNetwork entry to point to your desired JSON-RPC network:

Local Node

Testnet

To ensure you are targeting the correct network, you can query for a list of accounts available to you from your default network provider:

Deploying a Smart Contract

You will see that a default smart contract, written in Solidity, has already been provided under contracts/Greeter.sol:

This contract allows you to set and query a string greeting. Hardhat also provides a script to deploy smart contracts to a target network; this can be invoked via the following command, targeting your default network:

Hardhat also lets you manually specify a target network via the --network <your-network> flag:

Local Node

Testnet

Finally, try running a Hardhat test:

Last updated