2024-08-06 04:41:40 +08:00
2024-08-06 20:52:02 +08:00
2024-08-06 18:49:09 +08:00
2024-08-06 16:14:38 +08:00
2024-08-02 15:29:09 +08:00
2024-08-06 20:52:02 +08:00
2024-08-06 20:52:02 +08:00
2024-08-03 07:41:35 +08:00
2024-08-04 04:51:48 +08:00
2024-08-02 18:50:02 +08:00
2024-08-04 00:04:33 +08:00
2024-08-04 00:04:33 +08:00
2024-08-06 20:52:02 +08:00
2024-08-02 15:29:09 +08:00
2024-08-06 04:41:40 +08:00

Hardhat Simple Storage 🚀

Solidity Hardhat Yarn

A hands-on learning project building and shipping Solidity smart contracts with Hardhat — from a local node all the way to a verified deployment on the Sepolia testnet. This is my personal study ground for Web 3.0 smart-contract development.


📌 What I Learned in This Project

This repository documents my learning journey building smart contracts. Here's what it covers:

# Concept What I explored
1 Solidity fundamentals Data types (uint, int, address, string, bytes), state vs memory vs calldata, view/pure functions, structs, mappings, arrays
2 Hardhat workflow Local blockchain node (hardhat & ganache), compile, deploy, hardhat console, custom tasks
3 Contract deployment Both the classic scripts/ flow and the modern hardhat-deploy pattern with reusable deploy/ scripts
4 Real-world oracle integration Chainlink price feeds to value donations in USD (PriceConverter, FundMe) with mock deployment for local testing
5 Testing Unit tests + staging tests against Sepolia, --grep filtering, coverage reports
6 Gas optimization Coding patterns to reduce gas (prefer private, use constant/immutable) — verified with hardhat-gas-reporter
7 Code quality solhint best-practice linting, prettier + prettier-plugin-solidity formatting
8 Block explorer verification Auto-verification of contracts on Etherscan
9 Version control Git + Gitea workflow for source control
10 Security awareness Studied historical exploited contracts via rekt.news

📦 Smart Contracts

Contract Purpose
SimpleStorage.sol Core concepts: storage variables, data types, structs, mappings, view/pure functions
FundMe.sol Real-world pattern: accept ETH, track funders, withdraw with a minimum funding value in USD
PriceConverter.sol Library that converts ETH amounts to USD using a Chainlink price feed

Live Versions — Verified on Sepolia Testnet

This project has been successfully deployed AND verified on the EthSepolia testnet:

Deployed via Contract Address Etherscan (verified)
deploy.js script 0xc2022b56eBC140B5FebCf9FBaB14c17db4C315C4 View code
yarn hardhat deploy --network sepolia 0x3a827C119e1D746bb3C7bcbbf95c55246C8CcBdd View code

🛠️ Tech Stack

  • Solidity ^0.8.8 — smart contract language (EVM-compatible: Ethereum, Avalanche, Fantom, Polygon)
  • Hardhat 2.x — development environment
  • Ethers.js — Ethereum JavaScript library
  • hardhat-deploy — cleaner deployment workflow
  • Chainlink — decentralized price feeds
  • Node.js + Yarn — package management

🚀 Getting Started

Prerequisites

  • Node.js 18+ (this project used nvm install 18)
  • Yarn (corepack enable)
  • WSL on Windows (for the smoothest local setup)

Install & Compile

git clone https://github.com/hoelee/hardhat-simple-storage.git
cd hardhat-simple-storage

yarn add --dev hardhat prettier prettier-plugin-solidity dotenv \
  @nomiclabs/hardhat-ethers@npm:hardhat-deploy-ethers ethers \
  hardhat-gas-reporter solidity-coverage solhint

yarn hardhat compile

Run Tests (Local)

yarn hardhat test          # unit tests
yarn hardhat test --grep <keyword>   # run matching tests only
yarn hardhat coverage      # test coverage report

Local Development Node

yarn hardhat node          # run local blockchain in a dedicated terminal
yarn hardhat console --network localhost   # interactive Solidity REPL
yarn hardhat deploy --tags mocks --network localhost   # deploy local price-feed mocks

Deploy to Sepolia

# classic script
yarn hardhat run scripts/deploy.js --network sepolia

# hardhat-deploy pattern
yarn hardhat deploy --network sepolia

Gas Reporting & Code Quality

yarn hardhat test          # produces ./gas-report.txt when ETHERSCAN_API_KEY .env is set
yarn solhint contracts/*.sol
yarn prettier --write .    # format Solidity + JS

🧠 Key Takeaways (Gas Optimization)

Working on-chain made me think hard about cost:

  • Prefer private over public — avoids auto-generated (and expensive) getters
  • Use constant / immutable for values set once at deploy time
  • Remember: blockchain storage (store) and retrieval (read) cost the most gas — minimize them

Blockchain charges a higher gas fee for storage operations than for bytecode; write minimal, optimized state.


📁 Project Structure

hardhat-simple-storage/
├── contracts/          # Solidity source (SimpleStorage, FundMe, PriceConverter)
├── deploy/             # hardhat-deploy scripts (mocks, fund-me, storage)
├── deployments/        # Saved deployment artifacts per network (localhost, sepolia)
├── ignition/           # Hardhat Ignition module
├── scripts/            # Classic deploy / fund / withdraw scripts
├── tasks/              # Custom Hardhat tasks (e.g. block-number)
├── test/               # unit/ + staging/ (Sepolia) tests
├── utils/              # Shared utilities
├── helper-hardhat-config.js  # Per-network config (price feeds, RPC URLs)
└── hardhat.config.js   # Hardhat configuration

⚠️ Known Issues

  • The dependency combination is old — worth a dependency-upgrade pass.
  • Personal-study project; feel free to fork and improve it.

Found a bug or have an idea? Open an issue using the issues tab above. 🙏


🛡️ Security Note

The rekt.news leaderboard is a great reference for learning from real-world exploited contracts — every smart-contract developer should study it to avoid repeating the mistakes of the past.


💼 Looking for a Web 3.0 Developer?

Hi, I'm Mr Hoelee 👋 — I enjoy building pragmatic, secure smart-contract solutions and I am open to Web 3.0 remote work.

I bring a full-stack background (PHP, Java, JavaScript) plus hands-on Blockchain (Solidity, Hardhat, ethers.js) experience to the table. Let's build something great together!


Support

If you find this project useful, you can buy me a coffee — every cup fuels more learning.


📄 License

UNLICENSED — free to use, learn from, and build upon.

Description
Learning project: Solidity smart contracts (SimpleStorage, FundMe, PriceConverter) with Hardhat - deployment, testing, gas optimization, and Sepolia verification. Open to Web3 remote work.
Readme 1.4 MiB
Languages
JavaScript 99.4%
Solidity 0.6%