A comprehensive Hyperledger Fabric-based blockchain solution for agricultural supply chain traceability, providing transparent and immutable tracking from farm to consumer.
- Overview
- Features
- Architecture
- Prerequisites
- Installation
- Usage
- API Reference
- Testing
- Security
- Contributing
- License
This enterprise-grade blockchain solution implements end-to-end supply chain traceability using Hyperledger Fabric. The system tracks agricultural products through their entire journey, from harvest to consumer, ensuring:
- Transparency: Complete visibility of product movement
- Immutability: Tamper-proof record of all transactions
- Traceability: Real-time tracking and history access
- Compliance: Automated regulatory compliance checking
- Trust: Multi-party verification at each step
- Farmer records harvest details
- Transporter verifies and moves product
- Processor validates and processes
- Distributor manages packaging
- Retailer receives and sells
- Consumer verifies authenticity
-
Smart Contract Operations
- Asset creation and management
- Ownership transfers
- Multi-party approvals
- Compliance verification
- History tracking
-
QR Code System
- Dynamic QR generation
- Secure verification process
- History access through scanning
- Mobile-optimized interface
-
User Management
- Role-based access control
- Digital identity management
- Multi-signature support
- Organization management
-
Blockchain Network
- Multi-organization support
- Chaincode lifecycle management
- Private data collections
- State database (CouchDB)
-
Security
- TLS encryption
- CA-based authentication
- MSP-based authorization
- Audit logging
blockchain/
├── api/ # REST API implementation
├── chaincode-go/ # Smart contracts
├── config/ # Network configuration
├── test-network/ # Test network setup
└── builders/ # Custom chaincode builders
- Linux-based OS (Ubuntu 20.04 LTS recommended)
- 4GB RAM minimum
- 20GB available storage
- Docker v20.10.x or higher
- Docker Compose v2.0.x or higher
# System packages
sudo apt-get update
sudo apt-get install -y git curl wget jq
# Docker installation
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
# Go installation
wget https://go.dev/dl/go1.17.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.17.linux-amd64.tar.gz
echo "export PATH=$PATH:/usr/local/go/bin" >> ~/.bashrc
source ~/.bashrc
# Node.js
curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install -y nodejs- Clone Repository
git clone https://github.com/herbtrace/blockchain-supply-chain.git
cd blockchain-supply-chain- Network Setup
cd test-network
./network.sh up createChannel -c supplychannel -ca- Deploy Chaincode
./network.sh deployCC -ccn supplychain -ccp ../chaincode-go -ccl go- Start API Server
cd ../api
go mod tidy
go run main.go- Create Product Entry
curl -X POST http://localhost:3000/api/product/create \
-H "Content-Type: application/json" \
-d '{
"cropType": "Wheat",
"location": {"lat": 51.507351, "long": -0.127758},
"timestamp": "2023-09-18T10:00:00Z"
}'- Track Product
curl -X GET http://localhost:3000/api/product/{productId}/history- Generate QR
curl -X POST http://localhost:3000/api/qr/generate/{productId}- Verify QR
curl -X GET http://localhost:3000/api/qr/{qrId}/verify| Endpoint | Method | Description |
|---|---|---|
/api/product/create |
POST | Create new product |
/api/product/{id} |
GET | Get product details |
/api/product/{id}/history |
GET | Get product history |
| Endpoint | Method | Description |
|---|---|---|
/api/events/create |
POST | Record new event |
/api/events/{id} |
GET | Get event details |
# Run all tests
cd chaincode-go
go test ./... -v
# Run specific test suite
go test ./chaincode/smartcontract_test.go -v- TLS 1.3 encryption
- Mutual TLS authentication
- Private data collections
- Channel-based isolation
- Role-based access (RBAC)
- Organization-level MSP
- Certificate-based identity
- Policy-based endorsement
- Fork repository
- Create feature branch
- Commit changes
- Submit pull request