[Solidity] 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:
- Auto compile & deployment of code in development
- Auto builds & maintains a file with every contracts address & abi.
- A generic UI for your contracts, which hot reloads as contract code changes.
- A single command to deploy contracts to testnet & mainnet
- 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: https://github.com/mistersingh179/badass-hardhat-setup
Here are the steps for you to have this same setup:
- Clone this repo & install dependencies
git clone https://github.com/mistersingh179/badass-hardhat-setup
npm i
2. Then in a terminal window run the hardhat chain locally
npm run chain
3. Next, in another terminal window run the deployment script
npm run deploy
4. That's it. You should now have your chain running locally and code deploying to it in real-time.
Let's test our setup.
- Open your favorite IDE and you should see
*.sol
files in thecontracts
directory. - There should also be a file called
contract-addresses.json
being auto built everytime you change code. - 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. - For a UI, browse to app.sidekick.xyz, upload
contract-addresses.json
and press continue. You should have a UI for your contracts. - Make changes to your contracts now, you should see them also being updated in UI.
Deploy to testnet & mainnet
- When you are ready to deploy your code run
npm run deploy-goerli
ornpm run deploy-mainnet
- Then to verify the contracts do
npm run verify-goerli
ornpm run verify-mainnet
Writing new contracts
- To add a new contract, just add a
*.sol
file in thecontracts
directory. - 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. - That's it. 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