FRESH-CHAIN BLOCKCHAIN SOLUTION
The storage layer utilizes a methodology that combines blockchain and database technologies. This methodology enhances the scalability of the blockchain by reducing the overload on its chain. In other words, we only store the data necessary to make traceability immutable on the blockchain, while public data, such as information about products, organizations, and measurements, will be directed to the database. The two storage technologies will have a field that enables their connection.
We utilize Hyperledger Fabric v2.4.9 to establish our blockchain and its smart contract through JavaScript. Furthermore, we will leverage MongoDB, a NoSQL database, to develop the database.
The backend layer comprises two major components: Services and Application Programming Interfaces (APIs). The Services component employs Node.js, enabling efficient information management such as data creation, retrieval, and updating. This component communicates with both storage systems to send and retrieve data securely. The second component is the API, which uses Express. It facilitates seamless communication between the backend and the frontend applications.
The
frontend of our traceability platform uses React Native and React to build mobile and web applications, respectively. We communicate with APIs, enabling all actors in the value chain to view information about a product or lot.
Fresh produce blockchain traceability Implemented Platform
This section details the results relating to the implementation of the traceability platform, highlighting various steps in its development, starting with the blockchain, explaining the reason for the chosen consensus mechanism, and presenting the smart contract (chain code). After that, we
demonstrate some forms of automatic data collection in the platform. Next, we detail how our traceability algorithm works and present some of the most notable pages of the web application. Lastly, we show the results of the tests performed on the platform.
Fresh produce blockchain traceability Hyperledger Fabric
As mentioned before, we want a decentralized blockchain-based solution that meets our requirements. After evaluating several options, we chose Hyperledger Fabric v2.4.9 because of its balance between scalability and security, the possibility of creating smart contracts (called “chaincode” in Fabric) authored in different programming languages, such as Java, JavaScript, and Go, plus its optimization for various industries, including value chain management [47]. Another determinant feature is its capability of differentiating user roles, as it allows to build consortium and private blockchains.
Fresh produce blockchain traceability Consensus Mechanism
When developing a blockchain-based application, choosing the appropriate consensus mechanism is crucial. Hyperledger Fabric v2.4.9 provides several mechanisms, such as Raft and Solo, each with advantages and drawbacks. A thorough understanding of these mechanisms is essential to make an informed decision and build a robust blockchain application [48].
We wanted a decentralized application that balanced safety, scalability, and simplicity. After conducting a thorough analysis of consensus mechanisms provided by Hyperledger Fabric, we opted for Raft. This mechanism is the recommendation from Hyperledger Fabric and offers a decentralized solution that balances safety, scalability, and simplicity. Furthermore, the consensus algorithm is Crash Fault Tolerant (CFT), which ensures a high level of fault tolerance, making it well suited for our needs [48].
Hyperledger Fabric presents the opportunity to craft smart contracts using multiple programming languages. To maintain consistency across the platform’s development, we chose JavaScript. Our blockchain must enable the creation of activities and lots, permit the modification of activities, and facilitate the retrieval of all associated data.
To create an activity or a lot, we utilize the “writeData” function (as shown in Figure 8). This function requires the context, the transaction’s key (serves as the blockchain identifier), and a JSON containing all pertinent information as parameters. The key follows a sequential pattern and begins with “LOT” for a lot (e.g., LOT20) or “ACT” for an activity (e.g., ACT76).
To gather comprehensive information on lots or activities, we use the “readData” function (as depicted in Figure 9). This function entails two parameters—the context and a field used to distinguish activities or lots. If the value is A, the function will retrieve all activities. Otherwise, it will collect all the lots. After the condition, all records pass through an iterator and loops. To retrieve a single record, we use the “readSingle” method (Figure 10. This function receives as parameters the context and the key. The latter obtains the unique record.
To make changes to activities, we utilize the “updateData” function (as depicted in Figure 11). This function takes in the context, key, a control field for specifying the fields to update, and the data as its parameters. The activity’s status, end timestamp, and output lots (applicable upon completion) are the fields that can suffer updates.