The Future of Sustainable Transportation is Here
Production-ready blockchain platform for global EV charging with token rewards
- Overview
- Key Features
- Architecture
- Tech Stack
- Quick Start
- Installation
- Deployment
- API Documentation
- Database Schema
- Security Features
- Performance Metrics
- Environmental Impact
- Contributing
- License
DeWatt is a revolutionary blockchain-powered platform that transforms the EV charging experience into a rewarding, sustainable ecosystem. Built on Solana blockchain, DeWatt enables users to find charging stations worldwide, earn EvT tokens for every kWh charged, and participate in a thriving P2P marketplace.
Built for Cypherpunk Hackathon - DeCharge Side Track This project was developed as part of the Cypherpunk hackathon, focusing on decentralized charging infrastructure and blockchain-based incentivization for sustainable transportation.
- Global Coverage: 100+ charging stations worldwide
- Token Rewards: Earn 1 EvT token per kWh charged
- P2P Trading: Trade EvT tokens with other users
- NFT Marketplace: Exclusive eco-friendly digital assets
- Leaderboards: Compete and earn recognition
- Environmental Impact: Track your CO2 savings in real-time
- Real-time Station Data: Live availability and pricing
- Global Coverage: 100+ stations across continents
- Smart Booking: Instant reservations with USD balance
- Session Tracking: Unique charge IDs with blockchain verification
- Earn Tokens: 1 EvT per kWh charged
- Welcome Bonus: $100 USD + 50 EvT tokens (one-time)
- Real-time Balance: Live tracking of USD and EvT balances
- Blockchain Security: All transactions recorded on Solana
- Create Orders: Set custom buy/sell prices
- Instant Matching: Real-time order execution
- Secure Escrow: Protected transactions
- Complete History: Full transaction records
- Eco Collections: Environmentally-themed NFTs
- EvT Payments: Purchase with earned tokens
- Rare Assets: Exclusive digital collectibles
- User Inventory: Personal NFT collection
- Global Rankings: Top 100 users by CO2 saved
- Personal Stats: Detailed environmental impact
- Achievement Badges: Unlock rewards
- Real-time Updates: Live ranking system
graph TB
subgraph " Frontend Layer"
A[Next.js 14 App] --> B[React Components]
B --> C[Tailwind CSS]
B --> D[Framer Motion]
A --> E[Wallet Integration]
E --> E1[Phantom Wallet]
E --> E2[Solflare Wallet]
end
subgraph " API Layer"
F[Next.js API Routes] --> G[Rate Limiting]
F --> H[Input Validation]
F --> I[Authentication]
F --> J[Error Handling]
end
subgraph " Database Layer"
K[MongoDB Atlas] --> L[Users Collection]
K --> M[Sessions Collection]
K --> N[Orders Collection]
K --> O[Marketplace Collection]
L --> L1[User Balances]
L --> L2[CO2 Tracking]
M --> M1[Charge Sessions]
M --> M2[Transaction History]
end
subgraph " Blockchain Layer"
P[Solana Network] --> Q[EvT Token]
P --> R[Transaction Signing]
P --> S[Wallet Adapters]
Q --> Q1[Token Minting]
Q --> Q2[Token Transfers]
R --> R1[Signature Verification]
R --> R2[Transaction Broadcasting]
end
A --> F
F --> K
F --> P
E --> S
style A fill:#61dafb
style F fill:#0070f3
style K fill:#47a248
style P fill:#14c294
flowchart TD
A[ User Connects Wallet] --> B[ Welcome Bonus Check]
B --> C{First Time User?}
C -->|Yes| D[ Claim Welcome Bonus<br/>$100 USD + 50 EvT]
C -->|No| E[ Main Dashboard]
D --> E
E --> F[ Browse Charging Stations]
F --> G[ Select Station]
G --> H[ Book Session]
H --> I[ Pay with USD Balance]
I --> J[ Start Charging]
J --> K[ Earn EvT Tokens<br/>1 EvT per kWh]
K --> L[ Session Complete]
L --> M[ Update CO2 Savings]
E --> N[ P2P Trading]
N --> O[ Create Buy/Sell Order]
O --> P[ Execute Trade]
P --> Q[ Token Transfer]
E --> R[ NFT Marketplace]
R --> S[ Browse Items]
S --> T[ Purchase with EvT]
T --> U[ Add to Inventory]
E --> V[ Leaderboard]
V --> W[ View Rankings]
W --> X[ Achievement Badges]
style A fill:#e1f5fe
style E fill:#f3e5f5
style J fill:#e8f5e8
style K fill:#fff3e0
style P fill:#fce4ec
style T fill:#f1f8e9
flowchart LR
A[ Charge EV] --> B[ Earn EvT Tokens<br/>1 EvT per kWh]
B --> C[ Token Balance]
C --> D[ P2P Trading]
C --> E[ NFT Marketplace]
C --> F[ Staking Rewards]
D --> G[ Buy/Sell Orders]
G --> H[ Trade Execution]
H --> I[ Token Transfer]
E --> J[ Digital Assets]
J --> K[ Physical Rewards]
K --> L[ Eco NFTs]
B --> M[ CO2 Savings<br/>0.85 kg per kWh]
M --> N[ Leaderboard]
N --> O[ Achievement Badges]
style A fill:#e8f5e8
style B fill:#fff3e0
style C fill:#e1f5fe
style D fill:#fce4ec
style E fill:#f1f8e9
style F fill:#f3e5f5
sequenceDiagram
participant U as User
participant F as Frontend
participant A as API
participant D as Database
participant B as Blockchain
U->>F: Select Charging Station
F->>A: POST /api/charging/book
A->>D: Check User Balance
D-->>A: User Balance
A->>A: Validate Payment
A->>B: Create Transaction
B-->>A: Transaction Signature
A->>D: Save Session
D-->>A: Session Created
A-->>F: Booking Confirmed
F-->>U: Session Active
Note over U,B: Charging in Progress
U->>F: Complete Session
F->>A: POST /api/charging/complete
A->>B: Mint EvT Tokens
B-->>A: Tokens Minted
A->>D: Update Balances
A->>D: Calculate CO2 Savings
D-->>A: Updated Data
A-->>F: Session Complete
F-->>U: Tokens Earned + CO2 Saved
sequenceDiagram
participant S as Seller
participant B as Buyer
participant A as API
participant D as Database
participant BC as Blockchain
S->>A: Create Sell Order
A->>D: Save Order
D-->>A: Order Created
B->>A: Browse Orders
A->>D: Get Available Orders
D-->>A: Order List
A-->>B: Display Orders
B->>A: Execute Trade
A->>D: Lock Order
A->>BC: Transfer Tokens
BC-->>A: Transfer Complete
A->>D: Update Balances
A->>D: Mark Order Complete
D-->>A: Trade Complete
A-->>B: Trade Successful
A-->>S: Trade Notification
flowchart TD
A[ API Request] --> B[ Input Validation]
B --> C{Valid Input?}
C -->|No| D[ Validation Error]
C -->|Yes| E[ Wallet Authentication]
E --> F{Valid Signature?}
F -->|No| G[ Authentication Failed]
F -->|Yes| H[ Rate Limit Check]
H --> I{Within Limits?}
I -->|No| J[ Rate Limited]
I -->|Yes| K[ Database Query]
K --> L[ Blockchain Operation]
L --> M[ Success Response]
style A fill:#e1f5fe
style M fill:#e8f5e8
style D fill:#ffebee
style G fill:#ffebee
style J fill:#fff3e0
| Technology | Version | Purpose |
|---|---|---|
| Next.js | 14.0 | React framework with App Router |
| TypeScript | 5.0 | Type-safe development |
| Tailwind CSS | 3.3 | Utility-first styling |
| Radix UI | Latest | Accessible component primitives |
| Framer Motion | 11.0 | Smooth animations |
| Leaflet | 1.9.4 | Interactive maps |
| React Hook Form | 7.51 | Form management |
| Technology | Version | Purpose |
|---|---|---|
| Node.js | 20+ | Runtime environment |
| MongoDB | Latest | NoSQL database |
| Mongoose | Latest | ODM for MongoDB |
| Solana Web3.js | 1.94 | Blockchain integration |
| Wallet Adapters | Latest | Multi-wallet support |
| Service | Purpose |
|---|---|
| Vercel | Hosting and deployment |
| MongoDB Atlas | Database hosting |
| Solana Devnet | Blockchain network |
| GitHub Actions | CI/CD pipeline |
graph TB
subgraph " Client Layer"
A[Web Browser] --> B[Next.js App]
B --> C[Wallet Connection]
B --> D[Interactive Maps]
B --> E[Real-time Updates]
end
subgraph " Cloud Infrastructure"
F[Vercel Edge Network] --> G[Next.js API Routes]
G --> H[Rate Limiting]
G --> I[Input Validation]
G --> J[Authentication]
end
subgraph " Data Layer"
K[MongoDB Atlas] --> L[Users Collection]
K --> M[Sessions Collection]
K --> N[Orders Collection]
K --> O[Marketplace Collection]
L --> L1[User Balances]
L --> L2[CO2 Tracking]
M --> M1[Charge History]
N --> N1[P2P Orders]
O --> O1[NFT Items]
end
subgraph " Blockchain Layer"
P[Solana Network] --> Q[EvT Token Program]
P --> R[Transaction Pool]
P --> S[Wallet Adapters]
Q --> Q1[Token Minting]
Q --> Q2[Token Transfers]
R --> R1[Transaction Verification]
S --> S1[Phantom Wallet]
S --> S2[Solflare Wallet]
end
A --> F
G --> K
G --> P
C --> S
style A fill:#e3f2fd
style F fill:#f3e5f5
style K fill:#e8f5e8
style P fill:#fff3e0
graph TB
subgraph " Global CDN"
A[Vercel Edge] --> B[Static Assets]
A --> C[API Routes]
A --> D[Serverless Functions]
end
subgraph " Database Cluster"
E[MongoDB Atlas] --> F[Primary Cluster]
E --> G[Read Replicas]
E --> H[Backup Cluster]
F --> F1[Users Shard]
F --> F2[Sessions Shard]
F --> F3[Orders Shard]
end
subgraph " Blockchain Network"
I[Solana Mainnet] --> J[RPC Endpoints]
I --> K[Transaction Validators]
I --> L[Token Programs]
J --> J1[Primary RPC]
J --> J2[Backup RPC]
end
subgraph " Security Layer"
M[Rate Limiting] --> N[Input Validation]
M --> O[Authentication]
M --> P[Encryption]
N --> N1[SQL Injection Prevention]
N --> N2[XSS Protection]
O --> O1[Wallet Signatures]
O --> O2[JWT Tokens]
end
A --> E
A --> I
A --> M
style A fill:#e1f5fe
style E fill:#e8f5e8
style I fill:#fff3e0
style M fill:#ffebee
flowchart TD
A[ EV Charging Session] --> B[ kWh Consumed]
B --> C[ CO2 Calculation<br/>0.85 kg per kWh]
C --> D[ Environmental Impact]
D --> E[ Update User Stats]
E --> F[ Leaderboard Ranking]
F --> G[ Achievement Unlocks]
D --> H[ Global CO2 Savings]
H --> I[ Platform Statistics]
I --> J[ Top Contributors]
G --> K[ Exclusive NFTs]
G --> L[ Physical Rewards]
G --> M[ Special Badges]
style A fill:#e8f5e8
style C fill:#fff3e0
style D fill:#e1f5fe
style F fill:#f3e5f5
style H fill:#e8f5e8
SECURITY NOTICE This is an open-source project. NEVER commit your
.env.localfile or any credentials to version control! Read the setup instructions for detailed security guidelines and setup instructions.
- Node.js 20+
- pnpm 8.15.6+
- MongoDB Atlas account (free tier available)
- Solana wallet (Phantom/Solflare)
git clone https://github.com/dewatt/dewatt.git
cd dewattpnpm install# Copy the example environment file
cp .env.example .env.local
# IMPORTANT: Edit .env.local with your actual credentials
# NEVER commit .env.local to version control!Required Configuration(edit .env.local):
# Database (Required)
MONGODB_URI=mongodb+srv://YOUR_USERNAME:YOUR_PASSWORD@cluster.mongodb.net/
DB_NAME=dewatt
# Blockchain (Required)
SOLANA_RPC_URL=https://api.devnet.solana.com
# Environment
NODE_ENV=developmentOptional Configuration:
# Admin access (generate with: openssl rand -hex 32)
ADMIN_API_KEY=your-generated-key
# Treasury wallet (for real blockchain transactions)
TREASURY_SECRET_KEY=[1,2,3,...,64]
# Contact form (if you want email functionality)
GOOGLE_CLIENT_ID=your-client-id
GOOGLE_CLIENT_SECRET=your-secret
GOOGLE_REFRESH_TOKEN=your-token
SENDER_EMAIL=your-email@gmail.com
CONTACT_RECIPIENTS=admin@example.compnpm run init-dbpnpm devVisit http://localhost:3000 to see DeWatt in action!
- Node.js: 20.0.0 or higher
- pnpm: 8.15.6 or higher
- Git: Latest version
- MongoDB Atlas: Free tier account
# Initialize database with sample data
pnpm run init-db
# Setup treasury wallet
pnpm run setup-treasury
# Check treasury balance
pnpm run check-treasury# Generate treasury keypair
solana-keygen new --outfile treasury-keypair.json
# Fund treasury (Devnet)
solana airdrop 2 <TREASURY_PUBLIC_KEY> --url devnet# Start development server
pnpm dev
# Build for production
pnpm build
# Start production server
pnpm start
# Run linting
pnpm lint
# Run type checking
pnpm type-checkSet these in your Vercel dashboard:
MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/
DB_NAME=dewatt
SOLANA_RPC_URL=https://api.devnet.solana.com
NODE_ENV=production
TREASURY_SECRET_KEY=[1,2,3,...,64]
ADMIN_API_KEY=your-secret-key- Create a new cluster
- Add your IP to whitelist
- Create database user
- Get connection string
- Update
MONGODB_URIin Vercel
# Switch to mainnet for production
SOLANA_RPC_URL=https://api.mainnet-beta.solana.comFROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
EXPOSE 3000
CMD ["npm", "start"]# Install dependencies
pnpm install --production
# Build application
pnpm build
# Start server
pnpm startAll API endpoints require wallet authentication via Solana signature verification.
GET /api/user/balance?wallet={address}Response:
{
"success": true,
"data": {
"usdBalance": 150.50,
"evTokenBalance": 250.75,
"totalKwh": 125.5,
"co2Saved": 106.675
}
}POST /api/user/welcome-bonus
Content-Type: application/json
{
"wallet": "9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM",
"signature": "base58_signature"
}POST /api/charging/book
Content-Type: application/json
{
"wallet": "9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM",
"stationId": "station_001",
"kwh": 25.5,
"signature": "base58_signature"
}GET /api/charging/session/{chargeId}POST /api/p2p/create
Content-Type: application/json
{
"wallet": "9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM",
"type": "sell",
"amount": 100,
"price": 0.5,
"signature": "base58_signature"
}POST /api/p2p/execute
Content-Type: application/json
{
"wallet": "9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM",
"orderId": "order_123",
"signature": "base58_signature"
}POST /api/market/purchase
Content-Type: application/json
{
"wallet": "9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM",
"itemId": "nft_001",
"signature": "base58_signature"
}GET /api/healthResponse:
{
"status": "healthy",
"timestamp": "2024-01-15T10:30:00Z",
"database": "connected",
"blockchain": "connected",
"treasury": "funded"
}interface User {
_id: ObjectId;
wallet: string; // Unique wallet address (indexed)
usdBalance: number; // USD balance
evTokenBalance: number; // EvT token balance
totalKwh: number; // Total kWh charged
co2Saved: number; // CO2 saved in kg (indexed)
welcomeBonusReceived: boolean;
createdAt: Date; // Account creation (indexed)
updatedAt: Date;
}interface ChargingSession {
_id: ObjectId;
chargeId: string; // Unique session ID (indexed)
stationId: string; // Charging station ID
wallet: string; // User wallet (indexed)
kwh: number; // Energy consumed
totalCost: number; // Cost in USD
status: 'active' | 'completed' | 'cancelled'; // Status (indexed)
explorerLink: string; // Solana explorer link
signature: string; // Transaction signature
memo: string; // Transaction memo
createdAt: Date; // Session start (indexed)
completedAt?: Date; // Session completion
}interface P2POrder {
_id: ObjectId;
wallet: string; // Creator wallet (indexed)
type: 'buy' | 'sell'; // Order type (indexed)
amount: number; // Token amount
price: number; // Price per token
status: 'open' | 'completed' | 'cancelled'; // Status (indexed)
buyer?: string; // Buyer wallet
createdAt: Date; // Order creation (indexed)
completedAt?: Date; // Order completion
}// Performance indexes
db.users.createIndex({ "wallet": 1 }, { unique: true });
db.users.createIndex({ "co2Saved": -1 });
db.users.createIndex({ "createdAt": 1 });
db.sessions.createIndex({ "chargeId": 1 }, { unique: true });
db.sessions.createIndex({ "wallet": 1, "createdAt": -1 });
db.sessions.createIndex({ "status": 1 });
db.orders.createIndex({ "type": 1, "status": 1 });
db.orders.createIndex({ "wallet": 1, "createdAt": -1 });This project implements multiple layers of security to protect user data and prevent abuse:
- All endpointsvalidate input parameters
- Type checkingwith TypeScript strict mode
- Sanitizationof user inputs
- SQL/NoSQL injectionprevention
- Wallet address format validation
// Rate limits per wallet address
const rateLimits = {
balanceQueries: '5 second cache',
chargingBookings: '10 requests/minute',
marketPurchases: '20 requests/minute',
welcomeBonus: '3 attempts/hour'
};- Wallet signature verificationfor all transactions
- Nonce-based authenticationto prevent replay attacks
- Session managementwith secure tokens
- Multi-wallet support(Phantom, Solflare)
- Admin API key protectionfor sensitive endpoints
- No hardcoded credentialsin source code
- Environment variable isolation(
.env.localnever committed) - Secure database connectionswith connection pooling
- HTTPS enforcementin production
- CORS configurationfor API security
- Sensitive data maskingin logs and errors
- Transaction verificationon Solana network
- Atomic operationswith rollback on failure
- Treasury wallet securitywith optional hardware wallet support
- Mock signaturesin development (no real funds at risk)
- Separate devnet/mainnetconfigurations
Before deploying or contributing:
- Never commit
.env,.env.local, or credential files - Use strong, unique passwords for MongoDB
- Generate secure admin API keys (
openssl rand -hex 32) - Keep treasury wallet keys in secure location
- Use different credentials for dev/staging/production
- Review all environment variables before deploying
- Test on Solana Devnet before Mainnet
- Enable rate limiting in production
- Monitor
/api/healthendpoint regularly - Keep dependencies updated
**CRITICAL:**The following files must NEVER be committed:
.env.env.local.env.*.localtreasury.jsonkeypair.json- Any file containing credentials
These are already in .gitignore - verify before committing!
| Operation | Target | Achieved |
|---|---|---|
| API Response (cached) | < 100ms | ~50ms |
| Database Queries | < 50ms | ~25ms |
| Blockchain Transactions | 1-3s | ~2s |
| Page Load Time | < 2s | ~1.5s |
| Time to Interactive | < 3s | ~2.5s |
- Concurrent Users: 10,000+ supported
- Database Connections: 2-10 pool size
- API Throughput: 1000+ requests/minute
- Blockchain TPS: 65,000+ transactions/second
// Health check endpoint
GET /api/health
// Detailed diagnostics (admin only)
POST /api/healthMetrics Tracked:
- Response times
- Error rates
- Database performance
- Blockchain connectivity
- Memory usage
- Request duration
// CO2 saved per kWh charged
const CO2_PER_KWH = 0.85; // kg CO2 per kWh
const co2Saved = kwhCharged * CO2_PER_KWH;- Real-time CO2 trackingfor each charging session
- Global leaderboardby environmental impact
- Achievement badgesfor sustainability milestones
- Carbon footprint visualizationin user dashboard
- Total CO2 Saved: Tracked globally and per user
- Green Energy Usage: Percentage of renewable energy
- Environmental Impact Score: User ranking system
- Sustainability Badges: Achievement system
We welcome contributions to DeWatt! Please read our contributing guidelines before getting started.
Documentation:
- the setup instructions - Security guidelines and best practices
- API Documentation - Complete API reference
- Fork the repository
- Clone your fork
git clone https://github.com/YOUR_USERNAME/dewatt.git
cd dewatt- Set up environment
pnpm install
cp .env.example .env.local
# Edit .env.local with your credentials (see Quick Start section)- Create a feature branch
git checkout -b feature/amazing-feature-
Make your changesand test thoroughly
-
Commit with conventional commits
git commit -m "feat: add amazing feature"- Push and create PR
git push origin feature/amazing-feature- Code Style: Follow TypeScript and React best practices
- Testing: Test your changes thoroughly before submitting
- Documentation: Update docs for user-facing changes
- Security: Never commit credentials or sensitive data
- Commits: Use conventional commit messages (feat/fix/docs/style/refactor/test/chore)
- Documentation: Update docs for API changes
- Security: Follow security best practices
- Bug Fixes: Report and fix issues
- New Features: Add functionality
- Documentation: Improve docs
- Testing: Add test coverage
- UI/UX: Improve user experience
- Security: Enhance security features
- Be respectful and inclusive
- Focus on constructive feedback
- Help others learn and grow
- Follow the project's coding standards
This project is licensed under the MIT License - see the LICENSE file for details.
MIT License
Copyright (c) 2025 DeWatt Contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
DeWatt was created for the Cypherpunk Hackathon - DeCharge Side Track, focusing on revolutionizing EV charging infrastructure through decentralized technology and blockchain integration.
Hackathon Focus:
- Decentralized EV charging infrastructure
- Token incentivization for sustainable transportation
- Blockchain-based reward system
- Global charging station network
For contributions and questions, please open an issue or submit a pull request on GitHub.