A blockchain-powered community recycling rewards system for Hack 4 Humanity
Tagline: Turn every gram of recycling into a verified, on-chain token.
GreenToken rewards people with GTN (GreenTokens) for recycling.
Every recycling action (material + weight) is written to a blockchain for transparency, and users receive tokens equal to grams recycled.
This builds trust (public ledger), accessibility (simple web UI), and accountability (verifiable history). It’s designed to help communities, schools, and local programs measure—and prove—their sustainability impact.
- On-chain records: each recycling action is stored (material, amount, timestamp, user).
- Auto-rewards: 1 GTN per gram recycled (configurable on contract).
- Wallet-based identity: users sign in via MetaMask; no passwords.
- Transparent history: anyone can view total recycling and user trends.
- Lightweight frontend: works in a browser with MetaMask + ethers.js.
- Optional analytics: export CSV/JSON for Wolfram Language charts.
- Smart Contracts: Solidity, Hardhat, OpenZeppelin
- Frontend: HTML + JavaScript + ethers.js (MetaMask)
- Wallet/Network: MetaMask on Polygon Amoy (or local Hardhat)
- Exporter/Analytics: Node.js scripts → CSV/JSON; optional Wolfram Language notebooks
- Hosting: Works on static hosts (GitHub Pages / Vercel) or Codespaces
Note: A React/Node backend version is easy to add, but this hackathon build focuses on a minimal, self-contained DApp to keep things simple for solo development in 3 days.
GreenToken/ ├─ contracts/ │ └─ GreenToken.sol # Solidity contract: addRecord, getUserRecords, getUserTokens ├─ scripts/ │ ├─ deploy.js # deploy to local or Amoy │ ├─ seed.js # seed sample records (local) │ └─ exportData.js # export on-chain records to data/ CSV+JSON ├─ frontend/ │ ├─ index.html # UI: connect wallet, submit, view balance/history │ ├─ abi/GreenToken.json # ABI (auto-written after deploy) │ └─ contractAddress.json # { address, chainId } (auto-written after deploy) ├─ analytics/ # (optional) Wolfram scripts & outputs ├─ data/ # exported records, deploy metadata ├─ .env.example # PRIVATE_KEY, RPC_URL_AMOY ├─ hardhat.config.js ├─ package.json └─ README.md
yaml Copy code
Create .env from the example and paste a testnet private key (NEVER your main wallet):
cp .env.example .env
bash Copy code
Edit .env:
PRIVATE_KEY=0x<64-hex-private-key> # from MetaMask (Account → Export Private Key) RPC_URL_AMOY=https://rpc-amoy.polygon.technology POLYGONSCAN_API_KEY=
yaml Copy code
Must be exactly
0x+ 64 hex characters (66 total).
Fund your test wallet with Amoy POL from a faucet.
# install deps
npm install
# compile contracts
npm run build
▶️ Run Locally (no testnet required)
Option A — One command (recommended):
bash
Copy code
./local_export_and_serve.sh
This will:
start a local Hardhat node (chainId 31337)
deploy the contract
export any logs to data/
serve the UI at http://127.0.0.1:8080
(In GitHub Codespaces, open the Forwarded Ports URL for 8080.)
Option B — Manual steps:
bash
Copy code
# Terminal A: local node
npx hardhat node
# Terminal B: deploy to localhost
npm run deploy:local
# (Optional) seed a few records
npx hardhat run --network localhost scripts/seed.js
# Export data (JSON+CSV)
npx hardhat run --network localhost scripts/exportData.js
# Serve the web app
npm run serve
🌐 Deploy to Polygon Amoy (testnet)
bash
Copy code
# Ensure .env is set and wallet has test POL (≥ 0.30 recommended)
npm run build
npm run deploy:amoy
After a successful deploy:
frontend/contractAddress.json is written (the app reads this automatically).
Open the app (http-server/Vercel) → Connect MetaMask → Switch to Amoy → use the form.
🧭 Using the App
Open the app (local or hosted)
Connect MetaMask → approve the connection
Switch to Polygon Amoy (if on testnet)
Submit a record: choose material (e.g., Plastic), amount in grams
Get tokens: you receive 1 GTN per gram
View: click “Show My GTN Balance” and “Show My Records”
📊 Optional: Wolfram Analytics
Export data then run Wolfram:
bash
Copy code
# Export (local or amoy; choose the matching network)
npx hardhat run --network localhost scripts/exportData.js
# or
npm run export:amoy
# If you’ve added analytics/analytics.wl:
wolframscript -file analytics/analytics.wl
Generates charts like total recycled, top recyclers, and trends over time in analytics/out/.
🧪 Judge Demo
Local: run ./local_export_and_serve.sh → app opens on port 8080
Testnet: run npm run deploy:amoy, open the hosted app, connect MetaMask on Amoy
Submit 2–3 records (Plastic, Paper, Glass). Show balance & history.
(Optional) Open the contract address on the Amoy explorer to show logs.
🤝 Contributing
PRs welcome! Please open an issue first for major changes. Keep PRs small and focused. Add a short note to the README if you add a new script or command.