๐ ๏ธ 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
- ๐ Smart Contract Framework: https://hardhat.org/getting-started/ย
- ๐ Git Helper: https://www.toptal.com/developers/gitignoreย
- ๐ Secrets Management: https://www.npmjs.com/package/dotenvย
๐ง 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...)
- The actual hex code stored on-chain (
- ๐บ๏ธ 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 -vSetup
mkdir tum-web3-week2
cd tum-web3-week2
npm init -y
npm install --save-dev hardhat
npx hardhat initChoose:
- 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
.envis 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 dotenvGet Your Private Key
- 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 sepoliaInside console:
await ethers.provider.getBlockNumber()โ๏ธ If it returns a number โ success.
๐ Part 5: First Deployment Script (15 min)
Script Logic
- Load contract factory
- Send deployment transaction
- Wait for confirmation
Run
npx hardhat run scripts/deploy.ts --network sepoliaVerify on Etherscan
- Copy deployed address
- Open Sepolia Etherscan
- Paste address
๐ You deployed a program to a global distributed network
โ Final Checklist
- Hardhat project initialized
- GitHub repo created & pushed
-
.gitignoreincludes.env -
.envcontains 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. ๐งฑโก