This project demonstrates the working of Merkle trees in blockchain technology to ensure transparency and reliability in food traceability. It utilizes a distributed immutable digital ledger to securely store and verify critical data in supply chain management, particularly in agriculture and food industries.
- Transparency & Reliability: Tracks and traces the reliability of food using blockchain.
- Immutable Ledgers: Ensures data cannot be edited, only recorded and distributed.
- Merkle Tree Structure: Uses a hash-based binary tree for efficient data verification.
- Cryptographic Security: Uses cryptographic hash functions to prevent tampering.
- QR Code Integration: Enables consumers to scan QR codes on product packaging to verify authenticity and traceability.
- Database Integration: Stores necessary details of food products in a MySQL database, connected via JDBC.
- Blockchain-based Validation: Verifies and secures information through Merkle root generation and blockchain integration.
- A Merkle tree is a hash-based data structure, generalizing a hash list.
- Typically implemented as a binary tree, where:
- Each leaf node is a hash of a block of data.
- Each non-leaf node is a hash of its children.
- Used in distributed systems for efficient data verification.
- Built using Merkle–Damgård construction with one-way compression functions.
- Provides strong collision resistance (brute-force attack would require 2²⁵⁶ attempts).
- Data Storage:
- A MySQL database stores product details (e.g., eggs, food items).
- JDBC is used to connect the project with the database.
- Merkle Tree Construction:
- Built using the database tables as data.
- Generates a Merkle root value for verification.
- Blockchain Integration:
- A Single Linked List (SLL) blockchain is generated with the same data fields.
- The blockchain is connected to the Merkle tree.
- Validation Process:
- An empty string array is generated based on the number of leaf nodes.
- Hash values are compared with existing hashes in the table.
- QR Code Implementation:
- A blockchain-enabled QR code is generated and printed on product packaging.
- Consumers scan the QR code to access certification details and timestamps.
This project implements a blockchain-based system for storing and accessing data securely. Here's an overview of the classes and their functionalities:
This class handles the major implementation of the code by calling methods from various classes based on user's choice via a switch case menu.
- Case 1: Inserts data into a singly linked list (SLL) with only the table name as the data in the SLL node.
- Case 2: Displays all the data stored in the SLL.
- Case 3: Generates a secret key for accessing classified data stored in the blockchain. Data is displayed only if the key matches for the respective company.
- Case 4: Allows tracing back to the origin of a product by scanning the blockchain-generated QR code.
- Case 5: Displays the Merkle root node hash, which is public.
This class describes the functionality and implementation of a Merkle Tree, a tamper-proof data structure. It creates a Merkle Tree only if the number of child nodes entered by the user is a power of two. Hash values of children and parent nodes are stored in ArrayLists. Parent hash values are calculated based on the position of child nodes in the ArrayLists. The Merkle Tree ensures data integrity by comparing child and parent node hash values with pre-calculated hash values. Access to data is granted if the root node matches the public root node hash.
Represents a block in the blockchain, containing fields such as timestamp, previous hash value, and table name. This block is used to insert data of type Node in the SLL.
Establishes a connection between the SQL databases and the Java code for data retrieval and storage.
Generates a blockchain-generated QR code used for tracing back to the origin of a product. Encodes a bit matrix and formats it to a barcode image.
Utilizes the SHA-256 hashing algorithm to generate hash values stored in the Merkle Tree for respective table names in the SLL.
Represent nodes used in different contexts. Node is used in the Merkle Tree, while Node1 represents blocks inserted into the SLL.
Creates a singly linked list with table names as data stored in the nodes. Blocks are added to the back of the SLL, establishing connections to SQL databases.
- Agriculture & Food Industry: Prevent counterfeits, ensure authenticity, and track GI-tagged products.
- Supply Chain & Logistics: Automate and optimize processes for greater efficiency.
- Public Safety & Transparency: Provide consumers with real-time access to verified product information.
This blockchain-based Merkle tree application is a robust solution for ensuring transparency and reliability in critical industries. By integrating cryptographic security and distributed ledger technology, it provides a scalable and secure method for product authentication and supply chain management.
- Run
Merkle_Main.java. - Use the switch case menu to perform various operations such as data insertion, display, access control, tracing, and viewing Merkle root hash.
- Java Development Kit (JDK)
- SQL Database
Feel free to explore and modify the code to fit your specific use case.

