Skip to content

spike-commander/ChainFair

Repository files navigation

ChainFair - Agricultural Supply Chain Transparency DApp

ChainFair Banner Solidity Polygon React Native

ChainFair is a blockchain-based DApp that addresses economic information asymmetry in agricultural supply chains. Consumers scan QR codes on produce to instantly reveal the full supply chain profit split, educating users on fair trade economics and empowering small farmers.

Problem Statement

Economic Information Asymmetry in Indian Agriculture

  • Farmer Share: Indian farmers receive only 10-15% of consumer price vs 40-60% in developed nations
  • Middlemen Dominance: 3-4 intermediaries each take 15-30% margin
  • Lack of Transparency: No way for consumers to verify fair trade claims
  • Education Gap: 73% of urban consumers unaware of farmer income challenges

"The biggest challenge facing Indian farmers is not production, but fair price discovery and market access." - NITI Aayog Agricultural Report 2023

Solution: ChainFair

ChainFair provides:

  1. Immutable Profit Records - Blockchain-verified supply chain data
  2. Consumer Education - Visual breakdown of where money goes
  3. Farmer Empowerment - Transparent pricing builds trust
  4. QR-Based Access - Mobile-first, no internet required for basic access

Tech Stack

Layer Technology Purpose
Blockchain Solidity + Polygon Mumbai Low-cost smart contracts (<$0.01/tx)
Storage IPFS (Pinata) Decentralized image/cert storage
Mobile React Native (Expo) Cross-platform QR scanner app
Dashboard Next.js Admin portal for farmers/retailers
Wallet ethers.js + MetaMask Web3 integration
Charts Recharts Profit visualization

Project Structure

chainfair/
├── contracts/
│   └── SupplyChain.sol          # Smart contract
├── scripts/
│   └── deploy.js                 # Deployment script
├── test/
│   └── SupplyChain.js            # Contract tests
├── frontend/app/
│   ├── App.js                     # React Native app
│   └── package.json
├── dashboard/
│   ├── src/pages/index.js         # Admin dashboard
│   └── package.json
├── .env.example
├── hardhat.config.js
└── README.md

Quick Start

Prerequisites

  • Node.js 18+
  • npm or yarn
  • MetaMask browser extension
  • Git

1. Clone & Install

git clone https://github.com/spike-commander/chainfair.git
cd chainfair
npm install

2. Smart Contract Setup

# Copy environment file
cp .env.example .env

# Edit .env with your values:
# POLYGON_MUMBAI_RPC=https://rpc-mumbai.maticvigil.com
# PRIVATE_KEY=your_private_key
# POLYGONSCAN_API_KEY=your_api_key

# Compile contracts
npm run compile

# Run local tests
npm run test

# Start local node
npm run node

# Deploy to local (separate terminal)
npm run deploy:local

# Deploy to Mumbai testnet
npm run deploy:mumbai

3. Frontend App

cd frontend/app
npm install
npm start

Scan QR code with Expo Go app or run on iOS/Android simulator.

4. Admin Dashboard

cd dashboard
npm install
npm run dev

Open http://localhost:3000

Demo Data

The deployment script creates 3 demo supply chains:

Product Farmer Price Consumer Price Farmer Share
Jabalpur Alphonso Mango ₹20 ₹200 10%
Jabalpur Organic Tomato ₹15 ₹150 10%
Kashmir Premium Apple ₹50 ₹300 17%

Smart Contract API

Functions

// Create new supply chain
createChain(string productName, string origin, uint256 farmerPrice, string ipfsHash, string certificationHash) returns uint256 tokenId

// Add stage to existing chain
addStage(uint256 tokenId, StageType stageType, string actorName, uint256 profitShareBPS, uint256 priceAtStage, string ipfsHash, string certificationHash) returns uint256 stageIndex

// Complete chain
completeChain(uint256 tokenId)

// Query chain data
getChain(uint256 tokenId) returns (productName, origin, totalPrice, farmerPrice, stageCount, isComplete, createdAt)

// Get profit split
getChainProfitSplit(uint256 tokenId) returns (profitShares[], stageNames[], totalPrice)

Events

event ChainCreated(uint256 indexed tokenId, string productName, string origin, uint256 farmerPrice);
event StageAdded(uint256 indexed tokenId, StageType stageType, address actor, uint256 profitShareBPS, uint256 priceAtStage);
event ChainCompleted(uint256 indexed tokenId, uint256 totalPrice);

Features

Mobile App

  • QR code scanning using device camera
  • Real-time blockchain data fetching
  • Pie chart profit breakdown visualization
  • Multilingual support (English/Hindi)
  • Demo mode with pre-loaded data
  • Educational insights about fair trade

Admin Dashboard

  • Supply chain creation interface
  • Stage addition workflow
  • IPFS file upload for certifications
  • Analytics and metrics visualization
  • Farmer/retailer authorization

Blockchain Layer

  • Gas-optimized (<10K gas per transaction)
  • ERC-20 compatible profit shares (BPS)
  • Role-based access control
  • Event-driven architecture

Hackathon Criteria Alignment

Criteria ChainFair Implementation
Relevancy Addresses agri economics, blockchain code, consumer education
Technical Execution Solidity + Polygon + IPFS + React Native
Impact Direct benefit to MSME farmers, consumer awareness
Presentation Demo video ready, pitch deck included
Innovation Novel QR-blockchain bridge for rural India

IPFS Integration

Images and certifications are stored on IPFS to avoid blockchain bloat:

// Upload to IPFS
const ipfsHash = await ipfs.add(imageBuffer);
const gatewayUrl = `https://ipfs.io/ipfs/${ipfsHash}`;

// Store only hash on chain
await contract.createChain(productName, origin, price, ipfsHash, certHash);

Gas Optimization

  • Packed structs for storage efficiency
  • Events instead of storage for historical data
  • Batch operations where possible
  • Estimated cost: ~8-10K gas per stage addition

Environment Variables

# Blockchain
POLYGON_MUMBAI_RPC=https://rpc-mumbai.maticvigil.com
PRIVATE_KEY=0x...

# Verification
POLYGONSCAN_API_KEY=your_key

# Frontend
NEXT_PUBLIC_CONTRACT_ADDRESS=0x...

# IPFS
IPFS_PROJECT_ID=your_id
IPFS_API_KEY=your_key

Contributing

  1. Fork the repository
  2. Create feature branch (git checkout -b feature/amazing-feature)
  3. Commit changes (git commit -m 'Add amazing feature')
  4. Push to branch (git push origin feature/amazing-feature)
  5. Open Pull Request

License

MIT License - See LICENSE file

Acknowledgments

  • Chainlink Supply Chain Documentation
  • MDPI Blockchain in Agriculture Papers
  • Polygon Developer Documentation
  • OpenZeppelin Smart Contract Library

Contact


Built for Hackathonomics 2026 - Empowering agricultural transparency through blockchain

About

ChainFair is a decentralized application (DApp) that brings radical transparency to agricultural supply chains in India. When a consumer picks up a mango at a store in Mumbai, they have no idea how much of the ₹200 price actually reached the farmer in Jabalpur who grew it.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors