A decentralized carbon credits marketplace built on Solana using Rust and Anchor framework.
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
- 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
- Rust (latest stable version)
- Solana CLI
- Anchor
- Node.js (v16 or later)
- Yarn
- Clone the repository:
git clone <repository-url>
cd carbon-marketplace-solana- Install dependencies:
yarn install- Build the program:
anchor build- Generate the program ID:
anchor keys list-
Update the program ID in
Anchor.tomlandprograms/hack-carbon/src/lib.rs -
Deploy to localnet:
anchor deploy# Make the script executable (Linux/macOS)
chmod +x quick-start.sh
# Run the setup script
./quick-start.sh- Install Dependencies:
yarn install- Start Local Validator:
solana-test-validator- Build and Deploy:
anchor build
anchor deploy- Run Tests:
# Run all tests
anchor test
# Run interactive tests
yarn test:interactive
# Listen to events
yarn test:eventsThis project includes comprehensive testing capabilities:
anchor testRuns the complete test suite covering all program functionality.
yarn test:interactiveRuns a comprehensive interactive test that demonstrates:
- Program initialization
- Carbon credit minting
- Token transfers
- Credit retirement with reasons
- Authority management
- Error handling
yarn test:eventsStarts a real-time event listener to monitor all program events.
See TESTING.md for comprehensive testing instructions and scenarios.
programs/hack-carbon/src/lib.rs- Main program logicprograms/hack-carbon/src/state.rs- Account state definitionsprograms/hack-carbon/src/instructions/- Instruction handlersprograms/hack-carbon/src/errors.rs- Custom error definitionstests/- Test files
- Initialize - Sets up the carbon credits mint
- Mint Credits - Mints new carbon credits (admin only)
- Transfer Credits - Transfers credits between accounts
- Retire Credits - Burns credits to offset carbon footprint
- CarbonMint - Stores mint information and authority
- UserAccount - Stores user-specific data
- RetirementRecord - Records credit retirement details
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
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
MIT License