A blockchain-based platform for small businesses to mint, trade, and retire verified carbon credits as ERC-721 NFTs on Ethereum. Built with Solidity, Hardhat, and React.
Carbon credits represent verified reductions in COβ emissions β but traditional systems are opaque, slow, and prone to double-counting. CarbonChain solves this by putting the entire lifecycle of a carbon credit on-chain:
- Each credit is minted as an ERC-721 NFT β ownership is transparent and immutable
- Businesses can trade credits peer-to-peer through a decentralized marketplace
- Retired credits are permanently locked at the smart-contract level β mathematically impossible to re-trade or double-count
- A small 1% platform fee is collected on each sale to sustain the protocol
- View your full carbon credit portfolio at a glance
- Platform-wide stats: total credits issued, total COβ offset, active listings
- Browse all verified carbon credits listed for sale as NFTs
- Filter by price range or search by project name / ID
- Buy any listing by sending ETH directly β no intermediary
- View all credits you own
- List a credit for sale at any price
- Cancel an active listing
- Permanently retire a credit β locks it forever, preventing double-counting
- Mint new verified carbon credits with project metadata
- Live NFT card preview before minting
| Layer | Technology |
|---|---|
| Smart Contracts | Solidity 0.8.28, OpenZeppelin v5 |
| Local Blockchain | Hardhat 2.22 |
| Frontend | React 18 + Vite 5 |
| Wallet Integration | ethers.js v6 + MetaMask |
| Styling | Vanilla CSS (dark glassmorphism) |
CarbonChain/
βββ contracts/
β βββ CarbonCredit.sol # ERC-721 NFT with mint / retire / status logic
β βββ CarbonMarketplace.sol # P2P marketplace β list / buy / cancel
βββ scripts/
β βββ deploy.js # Deploy + seed 3 demo listings automatically
βββ frontend/
β βββ src/
β βββ contexts/ # WalletContext (MetaMask + ethers.js)
β βββ components/ # Navbar, CreditCard, ListingCard, Toast
β βββ pages/ # Dashboard, Marketplace, MyCredits, Issue
β βββ contracts/ # ABI + address files (auto-generated on deploy)
βββ hardhat.config.js
βββ package.json
- Node.js v18 or later β nodejs.org
- MetaMask browser extension β metamask.io
- Git
git clone https://github.com/AnkeshGG/CarbonChain.git
cd CarbonChain# Root (Hardhat + contracts)
npm install
# Frontend
cd frontend && npm install && cd ..npm run compileOpen Terminal A and keep it running:
npx hardhat nodeThis starts a local EVM at http://127.0.0.1:8545 and prints 20 test accounts (each with 10,000 test ETH).
Open Terminal B:
npm run deployThis deploys both contracts, mints 3 demo carbon credits, lists them on the marketplace, and writes the ABIs + addresses to frontend/src/contracts/ automatically.
Demo listings created:
| # | Project | COβ | Verifier | Price |
|---|---|---|---|---|
| #0001 | Amazon Reforestation 2024 | 100 tCOβe | Verra | 0.05 ETH |
| #0002 | Nordic Boreal Shield Protection | 200 tCOβe | Gold Standard | 0.12 ETH |
| #0003 | Mangrove Coast Marine Restoration | 75 tCOβe | Plan Vivo | 0.08 ETH |
Open Terminal C:
cd frontend
npm run devOpen http://localhost:5173 in your browser.
In MetaMask β Network dropdown β Add a custom network:
| Field | Value |
|---|---|
| Network Name | Hardhat Localhost |
| RPC URL | http://127.0.0.1:8545 |
| Chain ID | 31337 |
| Currency Symbol | ETH |
In MetaMask β Account icon β Import Account β paste this private key:
0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d
This is Hardhat Account #1 β pre-funded with 10,000 test ETH. It is NOT the seller, so you can buy listings for demonstration.
β οΈ These are publicly known test keys. Never use them on Mainnet or send real ETH to these addresses.
Click Connect Wallet in the app header β the 3 demo listings will appear instantly on the Marketplace page.
- ERC-721 NFT where each token represents 1 verified carbon credit
- Role-based access:
DEFAULT_ADMIN_ROLE,ISSUER_ROLE(via OpenZeppelin AccessControl) - Credit lifecycle:
Active β Listed β Active(tradeable) orβ Retired(permanent) - Retired credits are blocked at the transfer level β impossible to move or re-retire
- Fixed-price peer-to-peer listings; only token owners can list
- 1% platform fee sent to the fee recipient on every sale
- Reentrancy-protected via OpenZeppelin
ReentrancyGuard - Automatically resets credit status back to
Activeafter a successful purchase
Because this runs on a local Hardhat node, you can reset the entire blockchain to a clean state in seconds:
# Terminal A β restart the blockchain
Ctrl+C
npx hardhat node
# Terminal B β redeploy fresh contracts + listings
npm run deployThen in MetaMask: Settings β Advanced β Reset Account (clears nonce cache).
npm testThe test suite covers:
- Credit minting with valid / invalid parameters
- Role enforcement (only ISSUER_ROLE can mint)
- Credit retirement and double-retirement prevention
- Transfer blocking for retired credits
- Marketplace listing, buying, and cancellation
- Fee calculation and distribution
- Edge cases (zero price, wrong caller, already listed)
# Root
npm run compile # Compile Solidity contracts
npm run node # Start local Hardhat blockchain
npm run deploy # Deploy contracts to localhost + seed demo data
# Frontend
cd frontend
npm run dev # Start Vite dev server β http://localhost:5173
npm run build # Production build β frontend/dist/Contributions are welcome!
- Fork the repository
- Create a feature branch:
git checkout -b feature/your-feature - Commit your changes
- Push:
git push origin feature/your-feature - Open a Pull Request
- Follow Solidity best practices and add NatSpec comments to new functions
- Ensure all 17 existing tests pass before submitting a PR
- For frontend changes, test both connected and disconnected wallet states
This project is licensed under the MIT License β see the LICENSE file for details.
Ankesh Kumar
Built to explore the intersection of blockchain transparency and real-world environmental impact β demonstrating how smart contracts can eliminate double-counting in carbon credit markets.
- π GitHub: @AnkeshGG
- πΌ LinkedIn: Ankesh Kumar
- OpenZeppelin β Battle-tested ERC-721 and AccessControl implementations
- Hardhat β Seamless local Ethereum development environment
- Verra / Gold Standard / Plan Vivo β Real-world carbon credit verification standards that inspired the project's data model
- ethers.js β Clean and modern Ethereum library for the React frontend
π’ Active
- Version: 1.0.0
- Smart Contracts: Fully deployed and verified locally
- Network: Hardhat Localhost (Chain ID 31337)
Immutable provenance. Zero double-counting. Verified on-chain. πΏ
