Skip to content

Repository files navigation

MeterChain

A blockchain accountability layer for India's power grid — built for the MEITY National Blockchain Framework.

India's electricity sector loses an estimated ₹2.7 lakh crore annually to meter tampering, subsidy leakage, billing fraud, DISCOM payment defaults, REC market manipulation, and a near-absent demand response infrastructure. MeterChain is a working prototype that addresses all six failure modes through a permissioned Hyperledger Fabric network with six purpose-built channels, a full-stack dashboard, and a live integration of Central Electricity Authority (CEA) national grid data.


What's in This Repository

Artifact Description
artifacts/power-blockchain React + Vite dashboard — channel-by-channel views, analytics, governance, energy insights
artifacts/api-server Express 5 REST API — all channel data, CEA integration, Trust Services verification API
artifacts/meterchain-pitch 15-slide investor/ministry pitch deck
lib/db Drizzle ORM schema + PostgreSQL connection
lib/api-spec OpenAPI 3.1 spec + Orval codegen config
lib/api-client-react Auto-generated React Query hooks
lib/api-zod Auto-generated Zod validation schemas
docs/ Policy brief, software design, regulatory compliance notes, testing guide

The Six Channels

Channel Failure Addressed Key Feature
CH-1: Smart Meter Integrity AT&C losses (21.4% national avg) Cryptographically signed meter readings; 60-second tamper monitoring via MQTT/Modbus
CH-2: Subsidy Token DBT Ghost connections; 23% DBT leakage Soul-bound subsidy tokens; double-redemption cryptographically impossible
CH-3: PPA Settlement 45-day manual reconciliation; ₹6.5L Cr DISCOM debt Smart contract auto-settlement on verified delivery; 18.4-day avg simulated
CH-4: Theft Detection Electricity theft and bypass Statistical anomaly detection; peer cohort comparison across BPL/EWS/Agriculture/Industrial tiers
CH-5: REC Registry Double-issuance; siloed state registries National tamper-evident REC ledger; CERC RPO compliance verifiable in real time
CH-6: Demand Response 9,020 MW peak deficit; zero DR infrastructure On-chain DR contract dispatch, load verification, and INR auto-settlement

Tech Stack

Backend

  • Node.js 24 / TypeScript 5.9
  • Express 5
  • PostgreSQL + Drizzle ORM
  • Zod validation (zod/v4)
  • Orval (OpenAPI → React Query + Zod codegen)
  • esbuild (production CJS bundle)

Frontend

  • React 18 + Vite
  • Tailwind CSS
  • Recharts (data visualisation)
  • React Query (server state)
  • React Router v6

Pitch Deck

  • React + Vite (slides artifact)
  • Barlow Condensed + Inter fonts
  • Keyboard / arrow key navigation

Blockchain Reference Architecture

  • Hyperledger Fabric v2.5
  • PBFT consensus (deterministic finality, <2s)
  • Hybrid on-chain/off-chain data model (hashes + settlement amounts on-chain; raw telemetry off-chain via Merkle roots)

Data

  • 7 CEA API endpoints integrated (Power Supply Position, Renewable Energy Status, Annual Generation Report, and others)
  • All transaction data is simulated in this prototype; parameters calibrated against CEA national baselines

Project Structure

meterchain/
├── artifacts/
│   ├── api-server/           # Express API (port from $PORT env var)
│   │   └── src/
│   │       ├── routes/       # dashboard, insights, ppa, rec, dr, subsidy,
│   │       │                 # meters, governance, green-certs, verify, cea
│   │       └── cea-data/     # CEA processed.json — national grid context
│   ├── power-blockchain/     # Main web app
│   │   └── src/
│   │       └── pages/        # dashboard, meters, ppa, rec, demand-response,
│   │                         # subsidy, p2p-trading, governance, green-certs,
│   │                         # insights, analytics, architecture, docs, ...
│   └── meterchain-pitch/     # 15-slide pitch deck
│       └── src/
│           ├── pages/slides/ # Slide01Title … Slide15Closing
│           └── data/         # slides-manifest.json
├── lib/
│   ├── db/                   # Drizzle schema (smart meters, transactions,
│   │                         # subsidy, ppa, rec, dr, governance, green-certs)
│   ├── api-spec/             # openapi.yaml + orval.config.ts
│   ├── api-client-react/     # Generated React Query hooks
│   └── api-zod/              # Generated Zod schemas
├── scripts/                  # Seed scripts (run via pnpm filter)
├── docs/                     # Policy brief, design docs, compliance notes
├── render.yaml               # Render.com deployment config
├── DEPLOY.md                 # Step-by-step deployment guide (Neon + Render + Cloudflare)
├── pnpm-workspace.yaml
├── tsconfig.base.json
└── tsconfig.json

Getting Started

Prerequisites

  • Node.js 20+
  • pnpm 10+ (npm install -g pnpm)
  • PostgreSQL database (local or Neon free tier)

1. Install dependencies

pnpm install

2. Set environment variables

Copy .env.example (in artifacts/api-server/) and create a .env:

DATABASE_URL=postgresql://user:password@localhost:5432/meterchain
PORT=8080

3. Push the database schema

pnpm --filter @workspace/db run push

4. Seed sample data

Run all seed scripts in order:

pnpm --filter @workspace/scripts run seed-power
pnpm --filter @workspace/scripts run seed-subsidy
pnpm --filter @workspace/scripts run seed-ppa
pnpm --filter @workspace/scripts run seed-rec
pnpm --filter @workspace/scripts run seed-dr
pnpm --filter @workspace/scripts run seed-governance
pnpm --filter @workspace/scripts run seed-green-certs

5. Start the services

# API server (port 8080)
pnpm --filter @workspace/api-server run dev

# Main web app
pnpm --filter @workspace/power-blockchain run dev

# Pitch deck
pnpm --filter @workspace/meterchain-pitch run dev

Dashboard Pages

Route Page
/ Command Centre — cross-channel KPI summary + live activity feed
/meters Smart Meter Integrity — tamper alerts, consumption chart
/subsidy Subsidy Token DBT — beneficiary registry, settlement ledger
/ppa PPA Settlement — contracts, escrow status, settlement history
/rec REC Registry — certificate lifecycle, RPO compliance
/demand-response Demand Response — grid events, DR contracts, auto-settlements
/p2p-trading P2P Energy Marketplace — rooftop solar trades
/governance Governance Proposals — CERC/MEITY/MoP proposals and vote ledger
/green-certs Green Provenance Certificates — corporate sustainability certificates
/insights Energy Insights — 24-hour consumption, grid stress, DR nudges
/analytics Analytics — CEA national context, peer benchmarks
/architecture Architecture — Hyperledger Fabric channel diagram
/docs Platform Documentation

Trust Services Verification API

Read-only endpoints for external GovTech consumers:

GET /api/verify                    # Service catalogue
GET /api/verify/meter/:meterId     # Smart meter tamper status
GET /api/verify/rec/:recId         # REC lifecycle (retired → verified: false)
GET /api/verify/dr/:eventId        # DR event with settlement aggregates
GET /api/verify/subsidy/:tokenId   # Subsidy token disbursement
GET /api/verify/ppa/:contractId    # PPA contract escrow balance

Uniform response: { verified, recordId, channel, chaincode, txHash, verifiedAt, summary }


Pitch Deck

The 15-slide ministry/investor deck is at artifacts/meterchain-pitch/. Navigate with arrow keys or spacebar.

Slide Title
1 MeterChain — Title
2 The Scale of Loss — ₹2.7L Cr
3 Strait of Hormuz — India's Power Grid Is Downstream
4 Five Structural Failures
5 The Solution: MeterChain
6 Six Channels. Six Failures Solved.
7 CH-1 & CH-2: Meters + Subsidy
8 CH-3 & CH-4: PPA + Theft
9 CH-5 & CH-6: REC + DR
10 Prototype Simulation Results
11 Technical Architecture
12 Who Benefits and How (Stakeholders)
13 The Ask
14 Why Now — MEITY + MoP + CERC
15 Closing

Policy Brief

docs/meterchain-policy-brief.html — a self-contained, print-ready HTML document (~2,500 words) prepared for MEITY, Ministry of Power, and CERC. Open in any browser and print to PDF (Ctrl+P → Save as PDF) for A4 output.

Sections: Executive Summary · Five Failure Modes · Six-Channel Solution · Prototype Simulation Results · Regulatory Alignment · Implementation Roadmap · Three Specific Asks · Why Act Now (including the Hormuz LNG disruption analysis) · References (14 entries).


Deployment

See DEPLOY.md for the full step-by-step guide. Recommended free stack:

Service Provider Purpose
Database Neon Serverless PostgreSQL
API Vercel Serverless Node.js (vercel.json included)
API (alt) Render Long-running Node.js (render.yaml included)
Frontend Vercel Static + serverless
Frontend (alt) Cloudflare Pages Static site hosting

Important for Vercel: Set the Root Directory to / (the repo root), not artifacts/api-server. Vercel needs the full monorepo to resolve pnpm workspace packages (@workspace/db, @workspace/api-zod). The vercel.json at root handles routing automatically.


Prototype Disclaimer

All transaction data — meter readings, PPA settlements, subsidy tokens, REC certificates, DR contracts — is simulated. Parameters are calibrated against CEA national baselines and Indian power sector benchmarks (CEA Annual Report 2023-24, PFC Utility Performance Report 2022-23, MoP NEP 2023). The CEA API integration reflects real published CEA data. No live DISCOM billing systems or production blockchain nodes are connected in this prototype phase.


Regulatory Context

Framework Relevance
MEITY National Blockchain Framework 2022 Power sector use case
MoP National Electricity Plan 2023 AT&C 12% target by FY27; 10 GW DR by 2027
CERC RPO Regulations 2025 15% renewable purchase obligation; REC compliance
DBT Mission Guidelines (MoF) Leak-proof, auditable direct benefit transfers

Contributing

This is a prototype developed for the MEITY NBF Power Sector use case. Issues and pull requests are welcome.


License

MIT

About

A blockchain accountability layer for India's power grid

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages