This guide will help you connect the frontend (React) to the backend (Hardhat blockchain) so users can add projects and reports without needing MetaMask. The system uses cookie-based persistent user IDs stored in localStorage.
Make sure you have:
- ✅ Node.js installed
- ✅ npm installed
- ✅ Both
beandfefolders with dependencies installed
Open Terminal 1 (PowerShell):
cd d:\maxxing\be
npx hardhat nodeExpected Output:
Started HTTP and WebSocket JSON-RPC server at http://127.0.0.1:8545/
Accounts
========
Account #0: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266 (10000 ETH)
...
✅ Keep this terminal open! The blockchain needs to stay running.
Open Terminal 2 (PowerShell):
cd d:\maxxing\be
node scripts/deploy-simple.cjsExpected Output:
🚀 Deploying TransparencyLedger contract...
📝 Deploying from account: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
✅ TransparencyLedger deployed to: 0x5FbDB2315678afecb367f032d93F642f64180aa3
📝 IMPORTANT: Update this address in your frontend!
File: fe/src/utils/web3.js
const DEFAULT_CONTRACT_ADDRESS = "0x5FbDB2315678afecb367f032d93F642f64180aa3"
✅ Copy the contract address! You'll need it for the next step.
Open fe/src/utils/web3.js and update the contract address:
// Find this line (around line 18):
const DEFAULT_CONTRACT_ADDRESS = "0x5FbDB2315678afecb367f032d93F642f64180aa3"
// Replace it with your deployed contract address from Step 2
const DEFAULT_CONTRACT_ADDRESS = "YOUR_DEPLOYED_ADDRESS_HERE"In Terminal 2 (or open Terminal 3):
cd d:\maxxing\fe
npm run devExpected Output:
VITE v5.x.x ready in xxx ms
➜ Local: http://localhost:5173/
➜ Network: use --host to expose
✅ Open your browser and go to: http://localhost:5173/
-
First Visit:
- System generates a unique persistent ID (e.g.,
0x1a2b3c4d...) - ID is saved to
localStorageunder keyuser_id - This ID stays forever on the device (even after closing browser)
- System generates a unique persistent ID (e.g.,
-
Adding a Project:
- User fills out the form
- System uses ONE of the Hardhat test accounts (Account #0) to send the transaction
- User's cookie-based ID is recorded in the contract
- No MetaMask popup appears!
-
Viewing Data:
- All data is read from the blockchain
- Shows projects from all users
- Each project shows who added it
The backend uses Hardhat Account #0 as a "shared wallet" to send all transactions:
// In deploy-simple.cjs and web3.js
const privateKey = "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80";
const wallet = new ethers.Wallet(privateKey, provider);Important: This is ONLY for local development! Never use these keys in production!
- Open http://localhost:5173/
- Click "Add Project" button
- Fill in the form:
- Project Name: "Test Road Construction"
- Project Value: "1000000"
- Contractor: "ABC Company"
- Location: "Jakarta"
- Click "Add Project"
- ✅ Success popup appears with transaction hash
- ✅ Project appears in the list immediately
- ✅ No MetaMask popup!
- Click "Report Corruption" button
- Fill in the form:
- Related Project: Select a project (optional)
- Type: Choose corruption type
- Description: Write detailed description (min 20 chars)
- Anonymous: Check if you want anonymity
- Click "Submit Report"
- ✅ Success popup appears
- ✅ Go to "Laporan" page to see your report
- ✅ No MetaMask popup!
- Add a project
- Note your user ID (displayed in console or project details)
- Close the browser completely
- Reopen and visit the site
- Add another project
- ✅ Same user ID is used!
Solution:
- Make sure Hardhat node is running (Terminal 1)
- Check if the contract is deployed
- Verify contract address in
fe/src/utils/web3.js
Solution:
- Redeploy the contract:
node scripts/deploy-simple.cjs - Update the contract address in
fe/src/utils/web3.js - Restart the frontend server
Solution:
- Stop Hardhat node (Ctrl+C)
- Clear cache:
Remove-Item -Recurse -Force cache,artifacts - Restart Hardhat node
- Redeploy contract
Solution:
# Find and kill the process
Get-Process | Where-Object {$_.ProcessName -like "*node*"} | Stop-Process -Force┌─────────────────────────────────────────────┐
│ Frontend (React + Vite) │
│ Port: 5173 │
│ │
│ - Cookie-based User ID (localStorage) │
│ - web3.js (ethers.js integration) │
│ - No MetaMask required! │
└──────────────────┬──────────────────────────┘
│
│ HTTP Requests
│ (JSON-RPC)
▼
┌─────────────────────────────────────────────┐
│ Hardhat Local Blockchain Node │
│ Port: 8545 │
│ │
│ - 20 test accounts (each 10,000 ETH) │
│ - Uses Account #0 for all transactions │
│ - TransparencyLedger Contract │
└─────────────────────────────────────────────┘
For Local Development Only:
- ✅ Using Hardhat test accounts
- ✅ All private keys are publicly known (for testing)
- ❌ NEVER use these private keys in production
- ❌ NEVER deploy to mainnet with these keys
For Production:
- Use proper wallet management
- Implement server-side transaction signing
- Add authentication and authorization
- Use environment variables for sensitive data
d:\maxxing\
├── be/ # Backend
│ ├── contracts/
│ │ └── TransparencyLedger.sol # Smart contract
│ ├── scripts/
│ │ └── deploy-simple.cjs # Deployment script
│ ├── hardhat.config.ts # Hardhat config
│ └── package.json
│
└── fe/ # Frontend
├── src/
│ ├── components/
│ │ ├── AddProject.jsx # Add project form
│ │ └── ReportCorruption.jsx # Report form
│ ├── pages/
│ │ ├── Home.jsx # Main page
│ │ └── Reports.jsx # Reports page
│ └── utils/
│ └── web3.js # Blockchain integration
└── package.json
Before considering the setup complete, verify:
- Hardhat node is running on port 8545
- Smart contract is deployed successfully
- Contract address is updated in
fe/src/utils/web3.js - Frontend is running on port 5173
- Can add projects without MetaMask
- Can report corruption without MetaMask
- User ID persists across browser sessions
- All data is stored on blockchain
- Transaction hashes are displayed
Terminal 1 - Start Blockchain:
cd d:\maxxing\be && npx hardhat nodeTerminal 2 - Deploy & Start Frontend:
cd d:\maxxing\be && node scripts/deploy-simple.cjs
# Copy the contract address
# Update fe/src/utils/web3.js with the address
cd ..\fe && npm run devOpen Browser:
http://localhost:5173/
- Check Terminal 1 for blockchain logs
- Check Terminal 2 for frontend logs
- Check browser console (F12) for errors
- All transactions are logged in Terminal 1
Happy coding! 🎉