Skip to Content
๐ŸŽค Weekly presentations๐Ÿ› ๏ธ Hardhat & Web3 Dev Setup

๐Ÿ› ๏ธ Hardhat & Web3 Dev Setup

From User โ†’ Builder

This session is about learning how real Web3 developers work.
Not clicking buttons. Writing code that deploys to blockchains.


๐Ÿ“š Essential Resources


๐Ÿง  Theory & Core Concepts

Before touching code, you must understand what you are actually doing.


1๏ธโƒฃ What is Hardhat?

Hardhat is a professional Ethereum development environment.

Why not Remix?

  • Remix is great for demos.
  • It is not how production engineers work.

Hardhat gives you:

  • ๐Ÿ”จ Compilation
    • Solidity โ†’ Bytecode (EVM instructions)
    • Solidity โ†’ ABI (frontend communication map)
  • ๐Ÿงช Testing
    • Local blockchains that reset instantly
  • ๐Ÿค– Scripting
    • Automated deployments & interactions using JS/TS

Think of Hardhat as the VS Code + Docker + CI of Web3.


2๏ธโƒฃ Secrets Management (.env) โ€“ Do Not Get Hacked

๐Ÿ“– Learn more: For a detailed guide on environment variables, see Environment Variables

Golden Rule:
๐Ÿšจ Never commit private keys or API keys to GitHub. Ever.

Why?

  • Bots scan every GitHub commit globally.
  • Leaked key = wallet drained in seconds.

How .env works:

  • Local file with secrets
  • Loaded at runtime into memory
  • Ignored by Git

Analogy:

  • Code = car
  • .env = key
  • You publish the car, not the key

3๏ธโƒฃ Artifacts โ€“ What Are We Deploying?

When Hardhat compiles, it creates an artifacts/ folder.

It contains:

  • ๐Ÿงพ Bytecode
    • The actual hex code stored on-chain (0x608060...)
  • ๐Ÿ—บ๏ธ ABI (Application Binary Interface)
    • JSON description of how to interact with the contract
    • Used by frontends and scripts

ABI = instruction manual
Bytecode = machine


4๏ธโƒฃ RPC Nodes โ€“ Your Gateway to the Blockchain

Your laptop is not a blockchain node.

To interact with Ethereum, you need an RPC Provider:

  • Alchemy
  • Infura
  • Google Cloud Web3

Flow:
Hardhat โ†’ RPC Provider โ†’ Ethereum Network


๐ŸŽฏ What You Should Gain From This Session

๐Ÿš€ From User to Developer

  • Metamask โ†’ user tool
  • Hardhat โ†’ builder tool

๐Ÿ—๏ธ Professional Dev Setup

  • Node.js & npm
  • Secure key handling
  • Reproducible environments

๐Ÿง‘โ€๐Ÿ’ผ GitHub = Your CV

  • Web3 is open-source by default
  • Recruiters check:
    • Commit history
    • Repo structure
    • Security awareness

๐ŸŒ Blockchain โ€œHello Worldโ€

  • Local dev environment
  • Connect to Sepolia testnet
  • Deploy a real smart contract

๐Ÿงช Part 1: Project Initialization (10 min)

Prerequisite

node -v

Setup

mkdir tum-web3-week2 cd tum-web3-week2 npm init -y npm install --save-dev hardhat npx hardhat init

Choose:

  • TypeScript (recommended)
  • Project root: yes
  • Gitignore: yes

Verify

npx hardhat test

๐Ÿ™ Part 2: Git & โ€œThe CV Builderโ€ (10 min)

Initialize Git

git init git branch -M main

.gitignore (CRITICAL)

Ensure it includes:

.env node_modules coverage

โš ๏ธ If .env is pushed โ†’ assume compromise.

First Commit

git add . git commit -m "feat: initial hardhat setup"

โžก๏ธ Create a GitHub repo and push.


๐Ÿ” Part 3: Environment Variables & Security (15 min)

๐Ÿ“– Reference: For a comprehensive guide on environment variables in Web3, check out Environment Variables

Install dotenv

npm install dotenv

Get Your Private Key

  1. Metamask โ†’ Account Details โ†’ Show Private Key

โš ๏ธ Use a throwaway / dev wallet only

Create .env

SEPOLIA_RPC_URL="https://eth-sepolia.g.alchemy.com/v2/YOUR_API_KEY" PRIVATE_KEY="0x..."

โš™๏ธ Part 4: Hardhat Configuration (10 min)

Edit hardhat.config.ts:

import * as dotenv from "dotenv"; import { HardhatUserConfig } from "hardhat/config"; import "@nomicfoundation/hardhat-toolbox"; dotenv.config(); const config: HardhatUserConfig = { solidity: "0.8.24", networks: { sepolia: { url: process.env.SEPOLIA_RPC_URL, accounts: [process.env.PRIVATE_KEY || ""], }, }, }; export default config;

Test Connection

npx hardhat console --network sepolia

Inside console:

await ethers.provider.getBlockNumber()

โœ”๏ธ If it returns a number โ†’ success.


๐Ÿš€ Part 5: First Deployment Script (15 min)

Script Logic

  1. Load contract factory
  2. Send deployment transaction
  3. Wait for confirmation

Run

npx hardhat run scripts/deploy.ts --network sepolia

Verify on Etherscan

  1. Copy deployed address
  2. Open Sepolia Etherscan
  3. Paste address

๐ŸŽ‰ You deployed a program to a global distributed network


โœ… Final Checklist

  • Hardhat project initialized
  • GitHub repo created & pushed
  • .gitignore includes .env
  • .env contains RPC + private key
  • Sepolia configured in Hardhat
  • Deployment script executed
  • Contract visible on Etherscan

๐Ÿง  Final Thought

Web3 development is not about tokens.
It is about engineering discipline, security, and open source credibility.

Welcome to the builder side. ๐Ÿงฑโšก

Last updated on