faizack/Supply-Chain-Blockchain
Supply Chain Management Using Blockchain
Supply Chain Blockchain DApp
A decentralized supply chain management system built on Ethereum blockchain using Solidity smart contracts, Next.js, and Web3.js
Star • Fork • Report Bug • Request Feature
Table of Contents
- Overview
- Features
- Technology Stack
- Architecture
- Installation
- Running the Project
- Usage Guide
- Smart Contract Details
- Contributing
- License
Overview
Supply Chain Blockchain DApp is an open-source, blockchain-based supply chain management application built with Solidity smart contracts, Hardhat, Next.js, Web3.js, and MetaMask. It demonstrates how to build an end-to-end Ethereum decentralized application (dApp) for transparent, secure, and traceable pharmaceutical supply chains.
This repository is ideal for developers who want to learn:
- How to build a full-stack Ethereum dApp with Solidity, Hardhat, Next.js, and Web3.js
- How to design role-based access control and product lifecycle tracking on the blockchain
- How to integrate a smart contract backend with a modern React/Next.js frontend
Key Benefits
- Transparency: All transactions and product movements are recorded on the blockchain
- Security: Immutable records prevent tampering and fraud
- Efficiency: Automated processes reduce administrative overhead
- Traceability: Complete product journey from raw materials to consumer
- Decentralization: No single point of failure
Features
- Role-Based Access Control: Secure role assignment (Owner, Raw Material Supplier, Manufacturer, Distributor, Retailer)
- Product Management: Add and track products through the entire supply chain
- Supply Chain Flow: Manage product stages (Order → Raw Material Supply → Manufacturing → Distribution → Retail → Sold)
- Real-Time Tracking: Track products with detailed stage information and QR codes
- Modern UI: Responsive interface built with Next.js and Tailwind CSS
- Web3 Integration: Seamless connection with MetaMask wallet
- Mobile Responsive: Works well on desktop and mobile devices
Technology Stack
Frontend
- Next.js 14 - React framework with App Router
- TypeScript - Type-safe development
- Tailwind CSS - Utility-first CSS framework
- Web3.js - Ethereum blockchain interaction
- QRCode.react - QR code generation for product tracking
Backend/Blockchain
- Solidity ^0.8.19 - Smart contract programming language
- Hardhat - Ethereum development environment
- Ganache - Personal blockchain for development
- MetaMask - Web3 wallet integration
Development Tools
- Node.js 18+ - JavaScript runtime
- npm/yarn - Package management
- Git - Version control
Architecture
The application follows a decentralized architecture where:
- Smart Contracts (Solidity) handle all business logic and data storage on the blockchain
- Frontend (Next.js) provides the user interface and interacts with the blockchain via Web3.js
- MetaMask acts as the bridge between users and the Ethereum network
- Ganache provides a local blockchain for development and testing
System Flow
User → Next.js Frontend → Web3.js → MetaMask → Ethereum Network → Smart Contract
Supply Chain Flow
The product journey through the supply chain:
Order → Raw Material Supplier → Manufacturer → Distributor → Retailer → Consumer
Installation
Prerequisites
Before you begin, ensure you have the following installed:
- Node.js (v18 or higher) - Download
- Git - Download
- Ganache - Download
- MetaMask - Chrome Extension | Firefox Add-on
- VS Code (Recommended) - Download
Step 1: Clone the Repository
git clone https://github.com/faizack619/Supply-Chain-Blockchain.git
cd Supply-Chain-BlockchainStep 2: Install Dependencies
Install root dependencies (for Hardhat):
cd backend
npm install
cd ..Install client dependencies:
cd client
npm install
cd ..Step 3: Configure Ganache
- Open Ganache and create a new workspace
- Note the RPC Server URL (usually
http://127.0.0.1:7545orhttp://127.0.0.1:8545) - Copy the Chain ID (usually
1337or5777)
Step 4: Configure Hardhat
Update hardhat.config.ts with your Ganache network settings:
networks: {
ganache: {
url: "http://127.0.0.1:7545", // Your Ganache RPC URL
chainId: 1337, // Your Ganache Chain ID
accounts: {
mnemonic: "your ganache mnemonic" // Optional: if using mnemonic
}
}
}Step 5: Deploy Smart Contracts
Compile the smart contracts:
npx hardhat compileDeploy to Ganache:
npx hardhat run scripts/deploy.ts --network ganacheThe deployment script will automatically update client/src/deployments.json with the contract address.
Step 6: Configure MetaMask
-
Open MetaMask and click the network dropdown
-
Select "Add Network" → "Add a network manually"
-
Enter the following details:
- Network Name: Ganache Local
- RPC URL:
http://127.0.0.1:7545(or your Ganache URL) - Chain ID:
1337(or your Ganache Chain ID) - Currency Symbol: ETH
-
Click "Save"
-
Import an account from Ganache:
- In Ganache, click the key icon next to an account to reveal the private key
- In MetaMask, click the account icon → "Import Account"
- Paste the private key and click "Import"
Running the Project
Start Ganache
- Open Ganache application
- Create or open a workspace
- Ensure the server is running
Deploy Contracts (if not already deployed)
npx hardhat run scripts/deploy.ts --network ganacheStart the Frontend
cd client
npm run devThe application will be available at http://localhost:3000
Build for Production
cd client
npm run build
npm startUsage Guide
1. Register Roles
- Navigate to "Register Roles" page
- Only the contract owner can register new roles
- Add participants: Raw Material Suppliers, Manufacturers, Distributors, and Retailers
- Each role requires: Ethereum address, name, and location
2. Order Materials
- Go to "Order Materials" page
- Only the contract owner can create orders
- Enter product details: ID, name, and description
- Ensure at least one participant of each role is registered
3. Manage Supply Chain Flow
- Access "Supply Chain Flow" page
- Each role can perform their specific action:
- Raw Material Supplier: Supply raw materials
- Manufacturer: Manufacture products
- Distributor: Distribute products
- Retailer: Retail and mark as sold
4. Track Products
- Visit "Track Materials" page
- Enter a product ID to view its complete journey
- View detailed information about each stage
- Generate QR codes for product verification
Smart Contract Details
The SupplyChain.sol smart contract implements a comprehensive supply chain management system with the following features:
Roles
- Owner: Deploys the contract and can register other roles
- Raw Material Supplier (RMS): Supplies raw materials
- Manufacturer (MAN): Manufactures products
- Distributor (DIS): Distributes products
- Retailer (RET): Sells products to consumers
Product Stages
- Ordered (Stage 0): Product order created
- Raw Material Supplied (Stage 1): Raw materials supplied
- Manufacturing (Stage 2): Product being manufactured
- Distribution (Stage 3): Product in distribution
- Retail (Stage 4): Product at retailer
- Sold (Stage 5): Product sold to consumer
Key Functions
addRMS(),addManufacturer(),addDistributor(),addRetailer(): Register participantsaddMedicine(): Create new product ordersRMSsupply(),Manufacturing(),Distribute(),Retail(),sold(): Progress products through stagesshowStage(): Get current stage of a product
Contributing
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Contribution Guidelines
- Follow the existing code style
- Write clear commit messages
- Add tests for new features
- Update documentation as needed
- Read the full CONTRIBUTING.md before opening a pull request
- Follow the project CODE_OF_CONDUCT.md
- Look for issues labeled
good first issueorhelp wantedif you’re new to the project
License
This project is licensed under the MIT License - see the LICENSE file for details.
Documentation
External Resources
- Solidity Documentation
- Next.js Documentation
- React Documentation
- Hardhat Documentation
- Web3.js Documentation
- Ganache Documentation
- MetaMask Documentation
Show Your Support
If you find this project helpful, please consider:
- Starring the repository
- Forking the project
- Reporting bugs
- Suggesting new features
- Sharing the repository with others
Made with Solidity, Next.js, and Web3



.png)