How Hardhat can help jump-start your smart contract development

Hardhat can make your smart contract development process easier to build, test, and deploy 🎉 … so what is it?

Hardhat is an Ethereum development environment that helps developers manage and automate the recurring tasks inherent to building smart contracts and DApps. 

The two big selling points for me were: 1) It comes built-in with Hardhat Network, a local Ethereum network designed for development. 2) Solidity debugging, featuring stack traces, console.log() and error messages when transactions fail.

Best of all it’s easy to get started.

To install it, you need to create an npm project by creating a project folder, running npm init, and following its instructions. Once your project is ready run:

npm install --save-dev hardhat

Next to create a Hardhat project run npx hardhat in your project folder and you should see something like this (below).

Select “Create a basic sample project” which will prompt you to install Waffle and Ethers and generate scaffolding to get you up and running with quickly.

npm install --save-dev @nomiclabs/hardhat-waffle ethereum-waffle chai @nomiclabs/hardhat-ethers ethers

If you run npx hardhat accounts you’ll see a list of test accounts Hardhat generated to support local smart contract testing.

The sample project includes a simple smart contract to get us started found in the contracts/ named Greeter.sol. When you’re ready to test smart contract code you compile it using:

npx hardhat compile

The sample project comes with these tests that use Waffle and Ethers.js. You can use other libraries if you want. To test your smart contract code you can leverage test/sample-test.js to get started by running:

npx hardhat test

Next, we can spin up an in-memory instance of Hardhat Network to locally deploy our smart contract by running:

npx hardhat run scripts/sample-script.js

Once you get the basics of Hardhat down, you can explore using Hardhat to deploy your smart contract(s) to a live network such as Rinkeby or even the Ethereum Mainnet and connecting them to real users and wallets. For information on this next step check out these Hardhat docs. The exciting part is once you’ve reached this point you can begin deploying smart contracts to the Ethereum blockchain and then building decentralized applications to interact with them or serve as a basic front-end like this example below.

posted by Tyler Wolfe GitHub @tylererc20

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: