CropChain is a full-stack blockchain application demonstrating an agricultural product traceability solution using a hybrid approach. It leverages Hyperledger Fabric for an immutable audit trail, MySQL for scalable off-chain data storage, and IPFS for decentralized file storage.
Main dashboard showing product overview and blockchain connectivity status.
Product management interface for creating, shipping, and tracking agricultural products.
- β Immutable Product Tracking - Track agricultural products on the blockchain
- π Complete History - View full product lifecycle and ownership changes
- π¦ Supply Chain Management - Ship and receive products between parties
- π Decentralized Storage - Upload certificates and documents to IPFS
- π± QR Code Generation - Generate QR codes for product traceability
- π¨ Modern UI - React-based responsive user interface with Tailwind CSS
- π Hybrid Architecture - Combines blockchain immutability with database scalability
βββββββββββββββββββ
β React UI β
β (Port 3000) β
ββββββββββ¬βββββββββ
β
ββββββββββΌβββββββββββββββββββββββββββββββββββββ
β Node.js/Express Backend β
β β’ REST API β
β β’ Fabric Gateway SDK β
β β’ MySQL Connection Pool β
β β’ IPFS Client β
βββββ¬ββββββββββ¬βββββββββββββ¬βββββββββββββββββββ
β β β
β ββββββΌββββββ βββββΌβββββββ
β β MySQL β β IPFS β
β β (3306) β β (5001) β
β ββββββββββββ ββββββββββββ
β
βββββΌββββββββββββββββββββββββββββββββββββββββββ
β Hyperledger Fabric Network β
β β’ Orderer (7050) β
β β’ Peer (7051) β
β β’ CA (7054) β
β β’ Chaincode (Go) β
βββββββββββββββββββββββββββββββββββββββββββββββ
| Component | Technology | Version |
|---|---|---|
| Blockchain | Hyperledger Fabric | 2.2.0 |
| Backend | Node.js + Express.js | 18.x |
| Frontend | React + Tailwind CSS | 18.2.0 |
| Database | MySQL | 8.0 |
| File Storage | IPFS | Latest |
| Containerization | Docker + Docker Compose | Latest |
| Smart Contract | Go (Golang) | 1.x |
cropchain-project/
βββ app.js # Main Express application
βββ package.json # Backend dependencies
βββ Dockerfile # Application container
βββ docker-compose.yml # Multi-container orchestration
βββ start-network.ps1 # Windows startup script
βββ start-network.sh # Linux/Mac startup script
βββ TROUBLESHOOTING.md # Detailed troubleshooting guide
β
βββ chaincode/ # Hyperledger Fabric Smart Contract
β βββ cropchain.go # Go chaincode implementation
β βββ go.mod # Go module dependencies
β
βββ fabric-network/ # Fabric network configuration
β βββ configtx.yaml # Channel configuration
β βββ crypto-config.yaml # Crypto material configuration
β βββ connection-org1.yaml # Fabric SDK connection profile
β βββ crypto-config/ # Generated certificates and keys
β βββ channel-artifacts/ # Channel configuration files
β
βββ scripts/ # Setup and deployment scripts
β βββ setup-fabric.sh # Network initialization
β βββ setup-channel.sh # Channel setup
β βββ deploy-chaincode.sh # Chaincode deployment
β βββ generate-artifacts.sh # Crypto material generation
β
βββ ui/ # React frontend
β βββ src/
β β βββ App.jsx # Main React component
β β βββ main.jsx # React entry point
β β βββ index.css # Tailwind CSS styles
β βββ vite.config.js # Vite build configuration
β βββ tailwind.config.js # Tailwind configuration
β βββ package.json # Frontend dependencies
β
βββ db/
β βββ init.sql # MySQL database initialization
β
βββ bin/ # Fabric binaries
β βββ cryptogen # Certificate generator
β βββ configtxgen # Configuration generator
β βββ peer # Peer CLI tool
β
βββ wallet/ # Fabric identity wallet (generated)
- Docker Desktop (Windows/Mac) or Docker Engine (Linux)
- Git Bash or WSL (for Windows users)
- 8GB RAM minimum
- 20GB free disk space
.\start-network.ps1This script will:
- Stop and clean existing containers
- Start orderer, peer, and CA services
- Create the channel
cropchainchannel - Join the peer to the channel
# Use Git Bash or WSL
bash scripts/deploy-chaincode.shOr manually:
# Package chaincode
docker exec cli peer lifecycle chaincode package cropchain.tar.gz --path /opt/gopath/src/github.com/hyperledger/fabric/peer/chaincode --lang golang --label cropchain_1
# Install chaincode
docker exec cli peer lifecycle chaincode install cropchain.tar.gz
# Approve chaincode (replace PACKAGE_ID with actual value from install output)
docker exec cli peer lifecycle chaincode approveformyorg -o orderer.example.com:7050 --channelID cropchainchannel --name cropchain --version 1.0 --package-id PACKAGE_ID --sequence 1
# Commit chaincode
docker exec cli peer lifecycle chaincode commit -o orderer.example.com:7050 --channelID cropchainchannel --name cropchain --version 1.0 --sequence 1 --peerAddresses peer0.org1.example.com:7051docker-compose up -d app mysql ipfsOpen your browser and navigate to: http://localhost:3000
Click the "Connect to Blockchain" button in the header to initialize the Fabric connection.
Navigate to the "Create Product" tab:
- Enter Product ID (e.g.,
RICE001) - Select Product Type (Rice, Wheat, Coffee, etc.)
- Enter Farmer Name
- Add Description
- Optionally upload a certificate to IPFS
Use the "Manage Products" tab to:
- Ship products to a new owner
- Receive products and update ownership
Access the "View History" tab to:
- Query product history by ID
- See complete ownership and status changes
- View timestamps and transaction IDs
The "All Products" tab displays:
- All products on the blockchain
- Search and filter capabilities
- Current product status
POST /api/connect-blockchainInitialize connection to the Fabric network.
POST /api/products
Content-Type: application/json
{
"id": "RICE001",
"type": "Rice",
"farmerName": "John Farmer",
"description": "Premium Basmati Rice",
"ipfsHash": "QmXxx...",
"fileName": "certificate.pdf"
}POST /api/products/:id/ship
Content-Type: application/json
{
"newOwner": "Distributor A"
}POST /api/products/:id/receive
Content-Type: application/json
{
"newOwner": "Retailer B"
}GET /api/products/:id/historyGET /api/products/:id/qrcodeGET /api/products/queryAllPOST /api/upload
Content-Type: multipart/form-data
document: [file]docker psdocker logs cropchain_app --tail 50 -fdocker logs peer0.org1.example.com --tail 50 -fdocker exec cli peer chaincode query -C cropchainchannel -n cropchain -c '{"Args":["QueryAllProducts"]}'docker exec cli peer chaincode invoke -o orderer.example.com:7050 -C cropchainchannel -n cropchain -c '{"function":"CreateProduct","Args":["TEST001","Rice","TestFarmer","hash1","hash2"]}'docker-compose downdocker-compose down -v
docker system prune -f
.\start-network.ps1
bash scripts/deploy-chaincode.sh
docker-compose up -d app mysql ipfsFor detailed troubleshooting, see TROUBLESHOOTING.md
Containers not starting:
docker-compose down -v
.\start-network.ps1Blockchain connection fails:
- Ensure all containers are running:
docker ps - Check logs:
docker logs cropchain_app - Click "Connect to Blockchain" in the UI
Chaincode errors:
- Verify chaincode is committed:
docker exec cli peer lifecycle chaincode querycommitted --channelID cropchainchannel - Check chaincode container:
docker ps | grep dev-peer
- β Fixed CA container configuration
- β Updated connection profile for container networking
- β Changed to cryptogen-based admin identity
- β Disabled discovery service for compatibility
- β Fixed markdown linting issues
- β Added comprehensive spell checker dictionary
- β Simplified JavaScript code patterns
This project is created for educational purposes.
This is an educational project. Feel free to fork and experiment!
- Hyperledger Fabric Community
- Docker Community
- IPFS Community
Built with β€οΈ for Agricultural Supply Chain Traceability

