Skip to content

Priyanchew/Blockchain-Carbon-Marketplace

Repository files navigation

Carbon Marketplace - Solana Implementation

A decentralized carbon credits marketplace built on Solana using Rust and Anchor framework.

Overview

This project is a Solana implementation of a carbon credits token system that allows:

  • Minting carbon credits (admin only)
  • Transferring carbon credits between users
  • Retiring (burning) carbon credits with a reason
  • Tracking all carbon credit activities on-chain

Features

  • Secure Token Management: Built on Solana's SPL Token standard
  • Role-based Access Control: Only authorized accounts can mint new credits
  • Carbon Credit Retirement: Users can burn their credits to offset carbon footprint
  • Event Logging: All activities are logged on-chain for transparency
  • High Performance: Leverages Solana's fast and low-cost transactions

Prerequisites

Installation

  1. Clone the repository:
git clone <repository-url>
cd carbon-marketplace-solana
  1. Install dependencies:
yarn install
  1. Build the program:
anchor build
  1. Generate the program ID:
anchor keys list
  1. Update the program ID in Anchor.toml and programs/hack-carbon/src/lib.rs

  2. Deploy to localnet:

anchor deploy

Quick Start

Option 1: Automated Setup (Recommended)

# Make the script executable (Linux/macOS)
chmod +x quick-start.sh

# Run the setup script
./quick-start.sh

Option 2: Manual Setup

  1. Install Dependencies:
yarn install
  1. Start Local Validator:
solana-test-validator
  1. Build and Deploy:
anchor build
anchor deploy
  1. Run Tests:
# Run all tests
anchor test

# Run interactive tests
yarn test:interactive

# Listen to events
yarn test:events

Testing

This project includes comprehensive testing capabilities:

📋 Automated Tests

anchor test

Runs the complete test suite covering all program functionality.

🎮 Interactive Tests

yarn test:interactive

Runs a comprehensive interactive test that demonstrates:

  • Program initialization
  • Carbon credit minting
  • Token transfers
  • Credit retirement with reasons
  • Authority management
  • Error handling

🎧 Event Monitoring

yarn test:events

Starts a real-time event listener to monitor all program events.

📚 Detailed Testing Guide

See TESTING.md for comprehensive testing instructions and scenarios.

Program Structure

  • programs/hack-carbon/src/lib.rs - Main program logic
  • programs/hack-carbon/src/state.rs - Account state definitions
  • programs/hack-carbon/src/instructions/ - Instruction handlers
  • programs/hack-carbon/src/errors.rs - Custom error definitions
  • tests/ - Test files

API Reference

Instructions

  1. Initialize - Sets up the carbon credits mint
  2. Mint Credits - Mints new carbon credits (admin only)
  3. Transfer Credits - Transfers credits between accounts
  4. Retire Credits - Burns credits to offset carbon footprint

Accounts

  • CarbonMint - Stores mint information and authority
  • UserAccount - Stores user-specific data
  • RetirementRecord - Records credit retirement details

Security

This program follows Solana security best practices:

  • Input validation on all instructions
  • Proper account ownership checks
  • Protection against common attacks (reentrancy, overflow, etc.)
  • Role-based access control

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a Pull Request

License

MIT License

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors