Get a head start with badass hardhat workflow

mistersingh179

Mister Singh

Posted on November 21, 2022

Get a head start with badass hardhat workflow

In this article I will first show you what a badass hardhat setup looks like and then second I will teach you so you can have the same.

The 5 things a badass hardhat setup has:

  1. Auto compile & deployment of code in development
  2. Auto builds & maintains a file with every contracts address & abi.
  3. A generic UI for your contracts, which hot reloads as contract code changes.
  4. A single command to deploy contracts to testnet & mainnet
  5. A single command to verify contracts.

Now, let's take a look at this setup IRL:

The code for this badass hardhat setup is here.

Here are the steps for you to have this same setup:

  1. Clone this repo & install dependencies
git clone https://github.com/mistersingh179/badass-hardhat-setup
npm i
Enter fullscreen mode Exit fullscreen mode
  1. Then in a terminal window run the hardhat chain locally npm run chain
  2. Next, in another terminal window run the deployment script npm run deploy
  3. That's it. You should now have your chain running locally and code deploying to it in real-time.

Let's test our setup.

  1. Open your favorite IDE and you should see *.sol files in the contracts directory.
  2. There should also be a file called contract-addresses.jsonbeing auto built everytime you change code.
  3. Go ahead, change the code in the IDE and you should see in terminal that it is auto deploying and the contract-addresses.json has been updated.
  4. For a UI, browse to sidekick.xyz, upload contract-addresses.json and press continue. You should have a UI for your contracts.
  5. Make changes to your contracts now, you should see them also being updated in UI.

Deploy to testnet & mainnet

  1. When you are ready to deploy your code run npm run deploy-goerli or npm run deploy-mainnet
  2. Then to verify the contracts do npm run verify-goerli or npm run verify-mainnet

Writing new contracts

  1. To add a new contract, just add a *.sol file in the contracts directory.
  2. Then add a deployment script for that contract in deploy directory. Copy paste existing deployment scripts and just change the contract name. This way it is less prone to errors.
  3. The contract should get auto-deployed now.

This is it. You too now have a badass hardhat setup. 🥳🎉

FYI – In case you want to see how all this is setup, just take look at the hardhat.config.js file and read the documentation of hardhat & its plugin hardhat-deploy

💖 💪 🙅 🚩
mistersingh179
Mister Singh

Posted on November 21, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related