Neon EVM: How to Deploy Neon dApps Using Hardhat

Neon Labs
Neon Labs
Published in
4 min readOct 13, 2022

The third and final article in our Deploying Neon dApps series explores how to deploy Solidity dApps using Hardhat. (We previously discussed how to deploy Neon with Remix and Truffle.

Hardhat is a development and deployment tool for EVM contracts and applications. Of the three deployment tools explored in this series, Hardhat is the most versatile, allowing for plenty of customizable settings and secure deployment to Neon’s mainnet, devnet, and testnet. However, unlike Remix, hHardhat can only be used via a command-line interface, and is not an IDE.

Before You Begin

Before you start the tutorial below, make sure that the following is true:

  • MetaMask is installed on your device.
  • MetaMask is configured for the Neon EVM.
  • NodeJS v8.9.4 or later is installed on your device.
  • Git is installed on your device. On Windows, use Git Bash.

Follow this guide to install and configure MetaMask.

ERC-20 Tutorial

The following tutorial will explain how to deploy a simple ERC-20 token contract to the Neon Devnet using Hardhat.

Step 1: Install Hardhat

Using Git, clone the ERC-20 Hardhat project from Neon’s remote repository and navigate to it with the following commands:

Then, run the following command to install Hardhat and the dependencies necessary to run the example project:

If the above command results in an error, run the following command:

Step 2: Set Up MetaMask Accounts

To interact with the soon-to-be-deployed contracts, you’ll need to create two new accounts in MetaMask. Before you begin this step, make sure that MetaMask is connected to the Neon Devnet.

In MetaMask, create two new accounts. To create a new account in MetaMask, click on your current account’s icon in the top right of the MetaMask extension pop-up. A drop-down menu will appear. From the drop-down menu, select“Create an Account”.

Then, obtain some Devnet NEON tokens for these accounts using the NeonFaucet.

Next, click on the three vertical dots to the right of your currently displayed account name and wallet address. In this drop-down menu that opens, select “Account Details” then “Export Private Key”. Enter your password and select “Confirm” to get access to the private key for that account.

Copy both accounts’ private keys and paste them into the hardhat.config.js file in the project folder, replacing the placeholder text in lines 11 and 12 of that file. Make sure to prefix these keys with “0x” in the configuration file.

Step 3: Compile Contracts

To compile the project’s contracts (located in the “contracts/” folder), run the following command:

The output from this command should be similar to the following:

Step 4: Run Tests

To run the project tests before deploying, run the following command. It will compile the contracts, deploy them to the Neon Devnet, and run all the tests in the “tests/” folder to make sure the contracts are working as expected.

If the tests all pass, the output of this command should look something like this:

Step 5: Deploy Contracts

To deploy the project’s contracts, simply run the command below to run the deployment script in the “scripts/” directory:

You should see output in your terminal similar to the following:

Step 6: Connect Project to MetaMask

To use this newly deployed ERC-20-style Neon Devnet token with ease, follow these instructions to import the token as an asset in MetaMask. Use the “contract address” from the output in Step 5 for the “Token Contract Address” in the instructions.

Once you complete this final step, you will be able to see your new ERC-20 assets in the MetaMask profiles of the new test accounts.

Conclusion

Of the three tools for Neon deployment explored over the course of this article series, Hardhat is the most useful and versatile. With a variety of customization options available, plus the ability to deploy to Mainnet due to no security vulnerabilities like with Truffle, Hardhat is the go-to tool for developers looking to launch their project into the “real world” using Neon.

Visit the Neon docs for a complete tutorial on using Hardhat to deploy your dApps.

--

--