A comprehensive agricultural supply chain platform with blockchain integration, smart contracts, GPS tracking, QR code provenance, and decentralized auctions.
Platform Components:
βββ π Blockchain (Hardhat + Solidity)
β βββ AuctionContract - Decentralized crop auctions
β βββ TrackingContract - GPS shipment tracking
β βββ ProvenanceContract - Product lifecycle management
βββ ποΈ Backend (Node.js + Express + MongoDB)
β βββ ethers.js blockchain integration
β βββ QR code generation & validation
βββ π₯οΈ Frontend (React + Vite)
βββ Blockchain hooks (wallet connection)
βββ QR scanner/generator components
βββ Real-time GPS tracking UI
- Node.js 18+
- MongoDB (for user data)
- Git
# Clone and setup (Windows PowerShell)
git clone <your-repo>
cd agri-supply-chain
.\setup-blockchain.ps1# Install blockchain dependencies
cd blockchain && npm install
# Install backend dependencies
cd ../backend && npm install ethers qrcode
# Install frontend dependencies
cd ../frontend && npm install ethers qrcode jsqr
# Copy environment files
cp backend/.env.example backend/.env
cp frontend/.env.example frontend/.envcd blockchain
npx hardhat nodeStarts local Ethereum network on http://127.0.0.1:8545 (Chain ID: 31337)
cd blockchain
npx hardhat run scripts/deploy.js --network localhostDeploys AuctionContract, TrackingContract, ProvenanceContract
cd backend
npm run devAPI server on http://localhost:5000
cd frontend
npm run devReact app on http://localhost:3000
- Create crop auctions with quality assessments
- Real-time bidding with automatic finalization
- Transparent pricing and farmer verification
- Precise shipment location tracking (6 decimal precision)
- Emergency brake detection and alerts
- Real-time delivery status updates
- End-to-end product lifecycle tracking
- 7-stage verification (Farming β Retail)
- Immutable quality certifications
- MetaMask connection
- Multi-signature support
- Gas optimization
// Core Functions:
createAuction(cropType, quantity, basePrice, duration)
placeBid(auctionId, bidAmount)
finalizeAuction(auctionId)
getActiveAuctions()// Core Functions:
createShipment(productId, destination, estimatedDelivery)
updateLocation(shipmentId, latitude, longitude)
markDelivered(shipmentId)
getTrackingHistory(shipmentId)// Core Functions:
createProduct(farmerId, productType, harvestDate)
addStageRecord(productId, stage, location, evidence)
getProductByQR(qrCode)
getCertifications(productId)POST /api/blockchain/auction/create # Create new auction
GET /api/blockchain/auction/active # Get active auctions
POST /api/blockchain/tracking/update # Update GPS location
GET /api/blockchain/tracking/:id # Get tracking history
POST /api/blockchain/provenance/stage # Add provenance stage
GET /api/blockchain/qr/:code # Get QR product infoPOST /api/auth/register # User registration
POST /api/auth/login # User authentication
GET /api/products # Product catalog
POST /api/orders # Order managementNetwork Name: Hardhat Local
RPC URL: http://127.0.0.1:8545
Chain ID: 31337
Currency: ETH# Smart contract tests
cd blockchain
npx hardhat test
# Backend API tests
cd backend
npm test
# Frontend component tests
cd frontend
npm test- Contract not deployed: Run deployment script first
- MetaMask connection failed: Check network configuration
- GPS precision errors: Ensure coordinates Γ 10^6 format
- QR code generation: Verify backend qrcode dependency
# Blockchain logs
cd blockchain && npx hardhat console
# Backend logs
cd backend && tail -f logs/app.log
# Frontend dev tools
# Open browser DevTools β Console# Backend (.env)
BLOCKCHAIN_RPC_URL=https://mainnet.infura.io/v3/YOUR_KEY
PRIVATE_KEY=0x...
MONGODB_URI=mongodb://localhost:27017/agri-supply-chain
# Frontend (.env)
VITE_API_URL=https://your-api.com
VITE_BLOCKCHAIN_RPC=https://mainnet.infura.io/v3/YOUR_KEY- Deploy contracts to mainnet/testnet
- Update contract addresses in environment
- Configure production MongoDB
- Deploy backend to cloud service
- Build and deploy frontend
- Smart Contract Auditing: Uses OpenZeppelin standards
- ReentrancyGuard: Prevents reentrancy attacks
- Access Control: Role-based permissions
- Data Validation: Input sanitization on all endpoints
MIT License - Build the future of agriculture! π±
- Fork the repository
- Create feature branch (
git checkout -b feature/AmazingFeature) - Commit changes (
git commit -m 'Add AmazingFeature') - Push to branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Built with β€οΈ for sustainable agriculture and blockchain innovation πΎβοΈ
This project is licensed under the MIT License - see the LICENSE file for details.
- OpenWeatherMap for weather data API
- OpenStreetMap for mapping data
- Leaflet for interactive maps
- MongoDB for database solutions
- React and Node.js communities
For support, email support@agrihub.com or join our Slack channel.
- Blockchain Integration for supply chain transparency
- IoT Sensor Integration for real-time crop monitoring
- AI-powered Price Prediction using machine learning
- Mobile Apps for Android and iOS
- Payment Gateway Integration for seamless transactions
- Multi-language Support for global adoption
- Advanced Analytics Dashboard with business intelligence
- Third-party Integrations (weather, logistics, payment)
Built with β€οΈ for the agricultural community by AGrihub Team