Skip to content

Hexor-Hash/carbonledger

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

CarbonLedger

Verified carbon credits. Permanent retirement. Full provenance.
A decentralized carbon credit marketplace on Stellar where carbon projects mint tokenized RWAs, corporations buy and retire them on-chain, and every credit has an immutable audit trail from issuance to retirement.

Stellar Rust Next.js USDC License Status


Table of Contents


The Problem

The voluntary carbon credit market moves over $2 billion annually β€” yet it is riddled with:

  • Fraud β€” projects claiming credits for sequestration that never happened
  • Double-counting β€” the same tonne of CO2 sold to multiple buyers
  • Opacity β€” corporations have no way to verify what they actually bought
  • Greenwashing β€” retired credits with no on-chain proof of retirement
  • Inaccessibility β€” small projects cannot afford traditional registry fees

The result is a market where companies pay real money for carbon credits that may not represent real impact β€” and have no way to prove otherwise to regulators or the public.


The Solution

CarbonLedger puts the entire carbon credit lifecycle on Stellar:

  • Every credit is minted with a unique serial number β€” double counting is mathematically impossible
  • Every retirement is permanently irreversible on-chain β€” greenwashing is eliminated
  • Every credit carries full provenance β€” from project registration to satellite monitoring to issuance to transfer to retirement
  • Every retirement generates a beautiful verifiable certificate with a permanent public URL
  • The entire audit trail is publicly accessible without a wallet β€” regulators, journalists, and the public can verify everything

βš™οΈ How It Works

PROJECT DEVELOPER          CARBONLEDGER               CORPORATION
       β”‚                        β”‚                           β”‚
       │── Submit project ─────►│                           β”‚
       β”‚   (methodology +       β”‚                           β”‚
       β”‚    coordinates)        β”‚                           β”‚
       β”‚                        │◄── Oracle monitoring ─────│
       │◄── Project verified ───│    (satellite data)       β”‚
       β”‚                        β”‚                           β”‚
       │── Request issuance ───►│                           β”‚
       β”‚   (verified tonnes)    β”‚                           β”‚
       │◄── Credits minted ─────│                           β”‚
       β”‚   (serial numbers      β”‚                           β”‚
       β”‚    assigned)           β”‚                           β”‚
       β”‚                        │◄── Browse marketplace ────│
       β”‚                        │◄── Purchase credits ──────│
       │◄── USDC payment ───────│                           β”‚
       β”‚                        │◄── Retire credits ────────│
       β”‚                        β”‚    (beneficiary + reason) β”‚
       β”‚                        │──► Certificate issued ────►│
       β”‚                        β”‚    (permanent on-chain)   β”‚

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    NEXT.JS 14 FRONTEND                       β”‚
β”‚   Public Audit β”‚ Marketplace β”‚ Buy β”‚ Retire β”‚ Dashboard      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                            β”‚  @stellar/stellar-sdk
                            β”‚  @stellar/freighter-api
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                  SOROBAN CONTRACTS (Rust)                    β”‚
β”‚  carbon_registry β”‚ carbon_credit β”‚ carbon_marketplace        β”‚
β”‚  carbon_oracle                                               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                            β”‚  py-stellar-base
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚            ORACLE / VERIFICATION BRIDGE (Python)             β”‚
β”‚  verification_listener β”‚ price_oracle β”‚ satellite_monitor    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                            β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚          OFF-CHAIN LAYER (PostgreSQL + IPFS)                 β”‚
β”‚  Project docs β”‚ Credit batches β”‚ Retirements β”‚ Certificates  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Smart Contracts

CarbonLedger deploys 4 Soroban contracts written in Rust:

carbon_registry

Manages carbon project registration, verification, and lifecycle status.

Function Description
register_project() Submit a new carbon project for verification
verify_project() Accredited verifier approves a project
reject_project() Permanently reject a fraudulent project
suspend_project() Halt new issuance from project under investigation
update_project_status() Oracle pushes monitoring data on-chain
get_project() Query full project details

carbon_credit

Mints, transfers, and permanently retires tokenized carbon credits.

Function Description
mint_credits() Mint credits for verified projects with unique serial numbers
retire_credits() Permanently and irreversibly retire credits on-chain
transfer_credits() Transfer credits between accounts
verify_serial_range() Detect double issuance before minting
get_credit_batch() Query a credit batch by ID
get_retirement_certificate() Retrieve a permanent retirement certificate

carbon_marketplace

Handles credit listings, purchases, and bulk corporate buying.

Function Description
list_credits() List credits for sale with price per tonne
delist_credits() Remove an active listing
purchase_credits() Buy credits β€” USDC to seller, credits to buyer
bulk_purchase() Corporations buy from multiple projects in one tx
get_active_listings() Browse all available credits
get_listings_by_vintage() Filter credits by vintage year

carbon_oracle

Receives and validates off-chain monitoring and price data.

Function Description
submit_monitoring_data() Verifier pushes satellite monitoring data
update_credit_price() Push benchmark price per methodology and vintage
flag_project() Flag a project for investigation
is_monitoring_current() Returns false if no data in last 365 days
get_benchmark_price() Get current market price per methodology

Error Constants

pub enum CarbonError {
    ProjectNotFound          = 1,
    ProjectNotVerified       = 2,
    ProjectSuspended         = 3,
    InsufficientCredits      = 4,
    AlreadyRetired           = 5,
    SerialNumberConflict     = 6,
    UnauthorizedVerifier     = 7,
    UnauthorizedOracle       = 8,
    InvalidVintageYear       = 9,
    ListingNotFound          = 10,
    InsufficientLiquidity    = 11,
    PriceNotSet              = 12,
    MonitoringDataStale      = 13,
    DoubleCountingDetected   = 14,
    RetirementIrreversible   = 15,
    ZeroAmountNotAllowed     = 16,
    ProjectAlreadyExists     = 17,
    InvalidSerialRange       = 18,
}

πŸ› οΈ Tech Stack

Layer Technology
Smart Contracts Rust + Soroban SDK
Blockchain Stellar Mainnet / Testnet
Frontend Next.js 14 (App Router) + TypeScript
Wallet Freighter (@stellar/freighter-api)
Stellar SDK @stellar/stellar-sdk, soroban-client
Payment Token USDC on Stellar
Trading Stellar DEX (SDEX)
Oracle Bridge Python + py-stellar-base
Satellite Data Google Earth Engine / Planet Labs
Price Feeds Xpansiv CBL + Toucan Protocol
Database PostgreSQL + Prisma ORM
File Storage IPFS via Pinata
Auth JWT + Stellar keypair + SEP-0030
Backend API NestJS
Testing Rust unit tests + Stellar Testnet

Project Structure

carbonledger/
β”œβ”€β”€ contracts/
β”‚   β”œβ”€β”€ carbon_registry/
β”‚   β”‚   β”œβ”€β”€ src/lib.rs
β”‚   β”‚   └── Cargo.toml
β”‚   β”œβ”€β”€ carbon_credit/
β”‚   β”‚   β”œβ”€β”€ src/lib.rs
β”‚   β”‚   └── Cargo.toml
β”‚   β”œβ”€β”€ carbon_marketplace/
β”‚   β”‚   β”œβ”€β”€ src/lib.rs
β”‚   β”‚   └── Cargo.toml
β”‚   └── carbon_oracle/
β”‚       β”œβ”€β”€ src/lib.rs
β”‚       └── Cargo.toml
β”œβ”€β”€ oracle/
β”‚   β”œβ”€β”€ verification_listener.py
β”‚   β”œβ”€β”€ price_oracle.py
β”‚   β”œβ”€β”€ satellite_monitor.py
β”‚   └── requirements.txt
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ page.tsx
β”‚   β”‚   β”œβ”€β”€ projects/
β”‚   β”‚   β”œβ”€β”€ marketplace/
β”‚   β”‚   β”œβ”€β”€ buy/
β”‚   β”‚   β”œβ”€β”€ retire/
β”‚   β”‚   β”œβ”€β”€ dashboard/
β”‚   β”‚   β”œβ”€β”€ verify/
β”‚   β”‚   └── audit/
β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”œβ”€β”€ CreditCard.tsx
β”‚   β”‚   β”œβ”€β”€ RetirementCertificate.tsx
β”‚   β”‚   β”œβ”€β”€ ProvenanceTrail.tsx
β”‚   β”‚   β”œβ”€β”€ MarketplaceFilter.tsx
β”‚   β”‚   β”œβ”€β”€ BulkPurchaseCart.tsx
β”‚   β”‚   β”œβ”€β”€ AuditExplorer.tsx
β”‚   β”‚   β”œβ”€β”€ SerialNumberLookup.tsx
β”‚   β”‚   β”œβ”€β”€ OracleStatus.tsx
β”‚   β”‚   β”œβ”€β”€ Toast.tsx
β”‚   β”‚   β”œβ”€β”€ LoadingSkeleton.tsx
β”‚   β”‚   β”œβ”€β”€ ErrorBoundary.tsx
β”‚   β”‚   └── TransactionStatus.tsx
β”‚   β”œβ”€β”€ lib/
β”‚   β”‚   β”œβ”€β”€ stellar.ts
β”‚   β”‚   β”œβ”€β”€ soroban.ts
β”‚   β”‚   β”œβ”€β”€ freighter.ts
β”‚   β”‚   β”œβ”€β”€ carbon-utils.ts
β”‚   β”‚   β”œβ”€β”€ sdex.ts
β”‚   β”‚   β”œβ”€β”€ api.ts
β”‚   β”‚   └── wallet-errors.ts
β”‚   └── styles/
β”‚       └── design-system.ts
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ auth/
β”‚   β”‚   β”œβ”€β”€ projects/
β”‚   β”‚   β”œβ”€β”€ credits/
β”‚   β”‚   β”œβ”€β”€ retirements/
β”‚   β”‚   β”œβ”€β”€ marketplace/
β”‚   β”‚   └── oracle/
β”‚   └── prisma/schema.prisma
β”œβ”€β”€ .github/
β”‚   └── workflows/ci.yml
β”œβ”€β”€ .env.example
β”œβ”€β”€ docker-compose.yml
β”œβ”€β”€ Stellar.toml
└── README.md

Getting Started

Prerequisites

# Rust + Soroban
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustup target add wasm32-unknown-unknown
cargo install --locked soroban-cli

# Stellar CLI
cargo install stellar-cli

# Node.js 18+
node --version

# Python 3.10+
python3 --version

# PostgreSQL
psql --version

Clone the repo

git clone https://github.com/YOUR_USERNAME/carbonledger.git
cd carbonledger

Environment Variables

cp .env.example .env
# Stellar
STELLAR_NETWORK=testnet
STELLAR_RPC_URL=https://soroban-testnet.stellar.org
STELLAR_HORIZON_URL=https://horizon-testnet.stellar.org
NETWORK_PASSPHRASE="Test SDF Network ; September 2015"

# Contract Addresses (after deployment)
CARBON_REGISTRY_CONTRACT_ID=
CARBON_CREDIT_CONTRACT_ID=
CARBON_MARKETPLACE_CONTRACT_ID=
CARBON_ORACLE_CONTRACT_ID=

# Oracle Keypair
ORACLE_SECRET_KEY=
ORACLE_PUBLIC_KEY=

# Admin Keypair
ADMIN_SECRET_KEY=
ADMIN_PUBLIC_KEY=

# Database
DATABASE_URL=postgresql://user:password@localhost:5432/carbonledger

# IPFS
IPFS_API_URL=https://api.pinata.cloud
IPFS_API_KEY=
IPFS_SECRET_KEY=

# Satellite Data
GOOGLE_EARTH_ENGINE_KEY=
PLANET_LABS_API_KEY=

# Price Feeds
XPANSIV_API_KEY=
TOUCAN_API_KEY=

# JWT
JWT_SECRET=
JWT_EXPIRY=7d

πŸ”— Contract Deployment

cd contracts

# Build all contracts
cargo build --target wasm32-unknown-unknown --release

# Deploy carbon_registry
stellar contract deploy \
  --wasm target/wasm32-unknown-unknown/release/carbon_registry.wasm \
  --source ADMIN_SECRET_KEY \
  --network testnet

# Deploy carbon_credit
stellar contract deploy \
  --wasm target/wasm32-unknown-unknown/release/carbon_credit.wasm \
  --source ADMIN_SECRET_KEY \
  --network testnet

# Deploy carbon_marketplace
stellar contract deploy \
  --wasm target/wasm32-unknown-unknown/release/carbon_marketplace.wasm \
  --source ADMIN_SECRET_KEY \
  --network testnet

# Deploy carbon_oracle
stellar contract deploy \
  --wasm target/wasm32-unknown-unknown/release/carbon_oracle.wasm \
  --source ADMIN_SECRET_KEY \
  --network testnet

Save all returned contract IDs to your .env file.


Oracle Setup

cd oracle
pip install -r requirements.txt

# Start verification listener (polls every 6 hours)
python3 verification_listener.py

# Start price oracle (runs every 12 hours)
python3 price_oracle.py

# Start satellite monitor (webhook receiver)
python3 satellite_monitor.py

πŸ’» Frontend Setup

cd frontend
npm install
npm run dev

Open http://localhost:3000

Install Freighter wallet and switch to Testnet.


🐳 Run With Docker

docker-compose up --build

Running Tests

cd contracts

# Run all tests
cargo test

# Run per contract
cargo test -p carbon_registry
cargo test -p carbon_credit
cargo test -p carbon_marketplace
cargo test -p carbon_oracle

# With output
cargo test -- --nocapture

Test Coverage (30 tests across 4 contracts)

Contract Tests
carbon_registry 7 tests
carbon_credit 10 tests
carbon_marketplace 7 tests
carbon_oracle 6 tests

User Roles

Project Developer

  • Register carbon offset project with methodology and coordinates
  • Submit monitoring data for credit issuance
  • Track issued vs retired credits and receive USDC payments

Corporation

  • Browse credits by methodology, vintage year, country, and price
  • Purchase single or bulk credits from multiple projects
  • Retire credits and download permanent certificates for ESG reporting

Verifier

  • Accredited verifiers approve projects for credit issuance
  • Submit on-chain attestations for monitoring periods
  • Earn attestation fees per verified project

Public / Auditor

  • Browse full audit trail without wallet connection
  • Look up any serial number and see complete history
  • Verify retirement certificates via permanent public URL

Credit Lifecycle

Project Registered β†’ Verifier Approved β†’ Oracle Monitoring β†’
Credits Minted (serial numbers assigned) β†’ Listed on Marketplace β†’
Purchased by Corporation β†’ Retired On-Chain (irreversible) β†’
Certificate Issued (permanent public URL) β†’
ESG Report Filed 

Key Parameters

Parameter Value
Serial number uniqueness Globally enforced across all batches
Retirement Permanently irreversible on-chain
Oracle freshness 365 days maximum for monitoring data
Price cache TTL 24 hours temporary storage
Methodology score minimum 70 out of 100
Price deviation alert 15% single update threshold
Protocol fee 1% of each transaction

Roadmap

Phase 1 β€” Contracts

  • carbon_registry β€” project registration and verification
  • carbon_credit β€” mint, retire, transfer with serial numbers
  • carbon_marketplace β€” list, buy, bulk purchase
  • carbon_oracle β€” monitoring data and price feeds
  • 30 Rust unit tests
  • Stellar Testnet deployment

Phase 2 β€” Oracle Layer

  • Verification listener service
  • Xpansiv CBL price feed integration
  • Google Earth Engine satellite webhook
  • End-to-end oracle β†’ Soroban test

Phase 3 β€” Frontend

  • Freighter wallet integration
  • Public audit explorer (no wallet required)
  • Corporate bulk purchase flow
  • Retirement certificate PDF generator
  • Serial number lookup tool

Phase 4 β€” Mainnet

  • Smart contract security audit
  • Gold Standard and Verra VCS methodology validation
  • Mainnet deployment
  • Regulatory compliance review
  • Third party registry API integrations

Contributing

git checkout -b feat/your-feature-name
git commit -m "feat: add your feature"
git push origin feat/your-feature-name

Please follow:

  • Conventional Commits
  • CarbonError enum for all contract errors
  • Checks-effects-interactions in all Soroban contracts
  • Retirement must always be irreversible β€” never add logic that undoes it
  • No crypto jargon on buyer-facing pages

License

MIT License β€” see LICENSE for details.


Acknowledgements


Built on Stellar. Built for the planet.

⭐ Star this repo if CarbonLedger matters to you

Website Β· Audit Explorer Β· Twitter Β· Discord

About

A verified carbon credit marketplace on Stellar. Carbon projects mint tokenized credits as RWAs on Soroban, corporations buy and retire them with full provenance. Retirement is permanently irreversible on-chain.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • TypeScript 59.5%
  • Rust 29.6%
  • Python 10.1%
  • Other 0.8%