This is my first smart contract built and deployed with Hardhat 3, written in Solidity 0.8.28, and tested using Mocha + Chai + Ethers v6.
It implements a simple Faucet, which allows users to withdraw small amounts of ETH with a cooldown time between withdrawals.
Contract: Faucet.sol
Network: Sepolia (chainId 11155111)
Address: 0xcAC087aF249117F2a4Ef479c528749C858D6A8a2
Deployer: 0xeC0760E041Ff8C5377cCB8d123d90D3F96d0fba9
Verified on: Blockscout
A simple faucet that:
- allows anyone to fund it by sending ETH,
- allows each address to withdraw up to 0.1 ETH,
- enforces a 1-hour cooldown between withdrawals per address.
- Uses custom errors (
AmountZero,AmountTooHigh,CooldownActive,InsufficientFaucetBalance) → cheaper gas than revert strings. - Emits events:
Funded(address from, uint256 amount)Withdraw(address to, uint256 amount)
- Safe transfer pattern with
call{value: _amount}and CEI (Checks–Effects–Interactions).
All tests are simulated locally using Hardhat’s built-in network (no real gas or ETH needed).
Run the suite:
npx hardhat testIt covers:
- ✅ Faucet funding (receive +
Fundedevent) - ✅ Successful withdrawals within limits
- ✅ Reverts on zero or excessive amounts
- ✅ Reverts if faucet balance is insufficient
- ✅ Cooldown logic (
CooldownActiverevert + success after 1h)
Deployment script: scripts/deploy.ts
npx hardhat run scripts/deploy.ts --network sepoliaExpected output example:
Network: sepolia (chainId 11155111)
Faucet deployed to: 0xcAC087aF249117F2a4Ef479c528749C858D6A8a2
Deploy tx hash: 0x0359ebde17a703e77f9687fd41b70c4cc939ca6fd88fd96af334b4753ae1096c
Deploying contract with account: 0xeC0760E041Ff8C5377cCB8d123d90D3F96d0fba9
Make sure you have an API key in .env:
ETHERSCAN_API_KEY=your_key_here
Then run:
npx hardhat verify --network sepolia 0xcAC087aF249117F2a4Ef479c528749C858D6A8a2- Node.js ≥ 18
- Hardhat 3
- TypeScript
- Ethers v6
npm installSEPOLIA_RPC_URL=https://eth-sepolia.g.alchemy.com/v2/your-key
SEPOLIA_PRIVATE_KEY=0xabc123... # private key of your Sepolia wallet
ETHERSCAN_API_KEY=your-etherscan-key
| Command | Description |
|---|---|
npx hardhat compile |
Compile contracts |
npx hardhat test |
Run test suite |
npx hardhat run scripts/deploy.ts --network sepolia |
Deploy to Sepolia |
npx hardhat verify --network sepolia <address> |
Verify on Etherscan |
npx hardhat console --network sepolia |
Open interactive console |
Send ETH directly to the contract address:
0xcAC087aF249117F2a4Ef479c528749C858D6A8a2
Call:
withdraw(uint256 _amount)Example:
_amount = 0.05 ether
- Solidity 0.8.28
- Hardhat 3 + Ethers v6
- TypeScript
- Chai / Mocha for testing
- Dotenv for config
- Blockscout / Etherscan for verification
- ✅ Add
faucetBalance()public view - 🧪 Expand test coverage for reentrancy checks
- 🌐 Deploy also to Optimism testnet
- 📜 Write a frontend DApp with Viem + React to interact with the faucet
Made with ❤️ by Valentina First Smart Contract project – Ethereum Bootcamp @ Alchemy University (2025)