
Features implemented: - User authentication with JWT tokens and role-based access (developer/buyer) - Blockchain wallet linking and management with Ethereum integration - Carbon project creation and management for developers - Marketplace for browsing and purchasing carbon offsets - Transaction tracking with blockchain integration - Database models for users, projects, offsets, and transactions - Comprehensive API with authentication, wallet, project, and trading endpoints - Health check endpoint and platform information - SQLite database with Alembic migrations - Full API documentation with OpenAPI/Swagger Technical stack: - FastAPI with Python - SQLAlchemy ORM with SQLite - Web3.py for blockchain integration - JWT authentication with bcrypt - CORS enabled for frontend integration - Comprehensive error handling and validation Environment variables required: - SECRET_KEY (JWT secret) - BLOCKCHAIN_RPC_URL (optional, defaults to localhost)
Carbon Offset Trading Platform
A blockchain-enabled carbon offset trading platform that connects project developers with willing buyers. This platform allows project developers to list their carbon offset projects and enables buyers to purchase verified carbon credits through blockchain transactions.
Features
For Project Developers
- Register as a project developer
- Create and manage carbon offset projects
- Upload project verification documents
- Track project performance and sales
- Integrate with blockchain for tokenization
For Buyers
- Register as a buyer
- Browse verified carbon offset projects
- Purchase carbon credits
- Link blockchain wallets for transactions
- Track purchase history and carbon offset ownership
Blockchain Integration
- Wallet linking support (Ethereum-compatible)
- Smart contract integration for carbon credit tokens
- Transaction verification and tracking
- Secure blockchain-based ownership records
Tech Stack
- Backend: FastAPI (Python)
- Database: SQLite with SQLAlchemy ORM
- Authentication: JWT tokens with bcrypt password hashing
- Blockchain: Web3.py for Ethereum integration
- Database Migrations: Alembic
- API Documentation: OpenAPI/Swagger
Project Structure
├── main.py # FastAPI application entry point
├── requirements.txt # Python dependencies
├── alembic.ini # Database migration configuration
├── openapi.json # API specification
├── app/
│ ├── api/ # API endpoints
│ │ ├── auth.py # Authentication endpoints
│ │ ├── wallet.py # Wallet management endpoints
│ │ ├── projects.py # Project management endpoints
│ │ └── trading.py # Trading and marketplace endpoints
│ ├── core/ # Core functionality
│ │ ├── security.py # Authentication and security
│ │ └── deps.py # Dependency injection
│ ├── db/ # Database configuration
│ │ ├── base.py # SQLAlchemy base
│ │ └── session.py # Database session management
│ ├── models/ # Database models
│ │ ├── user.py # User model
│ │ ├── carbon_project.py # Carbon project model
│ │ ├── carbon_offset.py # Carbon offset model
│ │ └── transaction.py # Transaction model
│ ├── schemas/ # Pydantic schemas
│ │ ├── user.py # User schemas
│ │ ├── carbon_project.py # Project schemas
│ │ └── transaction.py # Transaction schemas
│ └── services/ # Business logic services
│ ├── blockchain.py # Blockchain integration
│ └── wallet.py # Wallet management
└── alembic/ # Database migrations
└── versions/ # Migration files
Installation
- Install dependencies:
pip install -r requirements.txt
- Run database migrations:
alembic upgrade head
- Set required environment variables:
export SECRET_KEY="your-secret-key-here"
export BLOCKCHAIN_RPC_URL="https://your-ethereum-rpc-url" # Optional, defaults to localhost
Running the Application
Start the development server:
uvicorn main:app --host 0.0.0.0 --port 8000 --reload
The application will be available at:
- API: http://localhost:8000
- Documentation: http://localhost:8000/docs
- Alternative Docs: http://localhost:8000/redoc
- Health Check: http://localhost:8000/health
Environment Variables
Variable | Description | Required | Default |
---|---|---|---|
SECRET_KEY |
JWT token secret key | Yes | - |
BLOCKCHAIN_RPC_URL |
Ethereum RPC endpoint | No | http://localhost:8545 |
API Endpoints
Authentication
POST /auth/register
- Register new user (developer or buyer)POST /auth/login
- User login
Wallet Management
POST /wallet/link
- Link blockchain wallet to user accountDELETE /wallet/unlink
- Unlink wallet from user accountGET /wallet/info
- Get wallet information and balancePOST /wallet/generate-test-wallet
- Generate test wallet for development
Project Management (Developers)
POST /projects/
- Create new carbon offset projectGET /projects/my-projects
- Get developer's projectsPUT /projects/{project_id}
- Update projectDELETE /projects/{project_id}
- Delete project
Marketplace & Trading
GET /projects/
- Browse all available projectsGET /projects/{project_id}
- Get project detailsPOST /trading/purchase
- Purchase carbon offsetsGET /trading/my-transactions
- Get user's transactionsGET /trading/marketplace
- Get marketplace statistics
System
GET /
- Platform informationGET /health
- Health check endpoint
Database Schema
Users
- User authentication and profile information
- Wallet linking for blockchain integration
- User types: "developer" or "buyer"
Carbon Projects
- Project details and metadata
- Verification status and documents
- Credit availability and pricing
- Blockchain contract information
Carbon Offsets
- Individual carbon credit tokens
- Serial numbers and vintage years
- Blockchain token IDs and hashes
- Ownership tracking
Transactions
- Purchase records and blockchain transactions
- Transaction status and confirmation details
- Gas usage and block information
Development
Database Migrations
Create a new migration:
alembic revision --autogenerate -m "Description of changes"
Apply migrations:
alembic upgrade head
Testing Wallet Integration
Use the test wallet generation endpoint to create wallets for development:
curl -X POST http://localhost:8000/wallet/generate-test-wallet
Security Features
- JWT-based authentication
- Password hashing with bcrypt
- Role-based access control (developer/buyer)
- Blockchain wallet verification
- Transaction signing and verification
Contributing
- Follow the existing code structure and patterns
- Use type hints for all functions and methods
- Add appropriate error handling and validation
- Update documentation for any API changes
- Test wallet integration thoroughly
License
This project is part of a carbon offset trading platform implementation.
Description
Languages
TypeScript
100%