Automatic generation of Ethereum-based Smart Contracts for Agri-Food Traceability System

There is a growing demand for transparency along the agri-food chain, both from customers and governments. The adoption of blockchain technology to enable secure traceability for the management of the agri-food chain, provide information such as the provenance of a food product and prevent food fraud, is emerging rapidly, due to the inherent trust and inalterability provided by this technology. However, developing the right smart contracts for these use cases is even more of a challenge than it is for those used in other fields. Several management systems for the agri-food chain based on blockchain technology and smart contract have been proposed, all however ad-hoc for a specific product or production process and difficult to generalize. In this paper, we propose a new approach to easily customize and compose general Ethereum-based smart contracts designed for the agri-food industrial domain, to be able to reuse the code and modules and automate the process to shorten development times, while keeping it safe and reliable. Starting from the definition of the real production process, we aim to automatically generate both the smart contracts to manage the system and the user interfaces to interact with them, thus producing a system that works semi-automatically. Additionally, we describe a honey production case study to show how our approach works. Future work will first extend the scope of the approach to other supply chains, furthermore, while the current platform used is Ethereum, in the future our approach will be easily extended to other blockchain platforms.


INTRODUCTION
Block chain technology is a new distributed, decentralized and immutable ledger database that can assure immutability and integrity of data without the need of a third trusted party.This is one of the reasons for which strong expectations exist on this technology to solve problems in sectors in which several untrusted actors have to work together, such as in the case of the agri-food industry.Block chain technology appeared for the rst time in 2008 when one or more developers under the pseudonym Satoshi Nakamoto published a paper on a P2P electronic cash system [1] based on a digital currency called Bitcoin.This currency is based on a block chain and does not need any intermediaries or central authority to transfer money from one person to another person.A block chain is a specific type of distributed database able to store data in a secure and immutable way, and simultaneously to create transparency of the data history.It is based on a technological protocol that enables data to be exchanged with third parties within the P2P network without the need for intermediaries, because participants interact anonymously with encrypted identities, through transactions.Each transaction must be validated by a community of users through a consensus process, and then recorded in the ledger by adding it to an immutable chain of blocks holding the transactions stored in every network node.Many companies and startups are already adopting, and working on block chain technology, trying to exploit the many advantages it promises, so we are experiencing a strong growth of ideas and applications.

LITERATURE SURVEY BLOCKCHAIN IN AGRICULTURE TRACEABILITY SYSTEMS: A REVIEW
Food holds a major role in human beings' lives and in human societies in general across the planet.The food and agriculture sector is considered to be a major employer at a worldwide level.The large number and heterogeneity of the stakeholders involved from different sectors, such as farmers, distributers, retailers, consumers, etc., renders the agricultural supply chain management as one of the most complex and challenging tasks.It is the same vast complexity of the agriproducts supply chain that limits the development of global and efficient transparency and traceability solutions.The present paper provides an overview of the application of block chain technologies for enabling traceability in the agrifood domain.Initially, the paper presents definitions, levels of adoption, tools and advantages of traceability, accompanied with a brief overview of the functionality and advantages of block chain technology.It then conducts an extensive literature review on the integration of block chain into traceability systems.It proceeds with discussing relevant existing commercial applications, highlighting the relevant challenges and future prospects of the application of block chain technologies in the agri-food supply chain.

A REVIEW ON AGRI-FOOD SUPPLY CHAIN TRACEABILITY BY MEANS OF RFID TECHNOLOGY
Radio Frequency Identification (RFID) is a technology which provides appealing opportunities to improve the management of information flow within the supply chain and security in the agri-food sector.Nowadays, food safety is considered a major requirement in several countries, in particular, the traceability of food products which is mandatory by law.Thus, technological implementation leading to traceability strengthening in the agri-food sector is crucial.The first aim of this review is to analyze the current developments in RFID technology in the agri-food sector, through an operative framework which organizes the literature and facilitate a quick content analysis identifying future research direction.RFID technology seems to be able to bring great opportunities to this sector; nevertheless, several constraints are slowing its adoption.This survey may provide readers with an exhaustive overview of opportunities and constraints for the wide adoption of RFID.The second aim of this review is to provide an updated analysis on the current developments of RFID technology for different product typologies within the agri-food industry, discussing at the same time its potential in technological and logistical development regarding different sectors of the production/distribution chain.As referenced here, RFID implementations in the agri-food sector are increasing at a fast rate, and technological advancement follows the applicability opportunities.However, real applications of RFID technologies are still limited because of various technical and economical obstacles which are also discussed.

A FOOD TRACEABILITY SYSTEM BASED ON BLOCKCHAIN AND RADIO FREQUENCY IDENTIFICATION TECHNOLOGIES
The frequent occurrence of food safety accidents at the global level has triggered consumer sensitivity.Establishing a food traceability system can effectively guarantee food safety and increase consumer confidence and satisfaction.Existing food traceability systems often ignore environmental factors that affect food quality at all stages of the supply chain, and the authenticity of the information obtained through traceability is difficult to guarantee.In this study, a food supply chain traceability model was established based on block chain and radio frequency identification (RFID) technologies.The model focused on the traceability of environmental data during the various stages of the food supply chain and combined a centralized database and block chain for data storage.The lot identification data of the various supply chain stages were stored in a centralized database, while the environmental data were stored in a block chain.Thereby, the authenticity and accuracy of the traceability data were ensured.The block chain part of the model has been simulated in the Ethereum test environment, and the experiment has achieved traceability of temperature data.

A REVIEW ON BLOCKCHAIN APPLICATIONS IN THE AGRI-FOOD SECTOR
Food security can benefit from the technology's transparency, relatively low transaction costs and instantaneous applications.A block chain is a distributed database of records in the form of encrypted blocks, or a public ledger of all transactions or digital events that have been executed and shared among participating parties and can be verified at any time in the future.Generally, the robust and decentralized functionality of the block chain is used for global financial systems, but it can easily be expanded to contracts and operations such as tracking of the global supply chain.In the precision agriculture context, Information and Communications Technology can be further implemented with a block chain infrastructure to enable new farm systems and e-agriculture schemes.

INTELLIGENT SMART CONTRACTS FOR INNOVATIVE SUPPLY CHAIN MANAGEMENT
We propose blockchains and smart contracts as enabling technologies for an innovative type of supply chain management, with the goal of achieving higher levels of collaboration between the companies participating in the chain, which in turn pays in the form of higher levels of profitability and economic health for the participating enterprises.Our proposal goes far beyond simply using blockchains as decentralized systems to track the origin and delivery of goods, which is what most of the current block chain projects on supply chains are focused on.In fact, we introduce a type of smart contract aimed to solve two of the main problems that hinder the efficiency and effectiveness of supply chains, namely trust and coordination.Solving the problem of trust amounts to the capability of establishing quickly and cheaply contractual relationships based on convergent business needs among parties that may not know each other, and therefore need to protect themselves from opportunistic or incorrect behavior.Solving the problem of coordination consists in creating, at convenient management costs, a control system capable of directing the objectives of the supply chain as a whole, so as to achieve a greater common good in the medium term, as an alternative to the state of affairs in which each participant pursues, on its own behalf, lower but immediate returns.Our smart contracts for innovative supply chain management replace human coordinators in tackling the problems above, thus eliminating one major obstacle to their effective solution, namely the need to trust the coordinator itself.Furthermore, in this way, by automating the process of coordination, they unburden the supply chain of a considerable management cost.Contracts of this kind not only automate contract execution as in standard smart contracts, but also adjust costs and compensations of the members of a supply chain, effectively taking up the role that was of human coordinators.Thus, we refer to them as "intelligent smart contracts."In the course of the paper, we will illustrate an innovative supply chain architecture based on intelligent smart contracts running on block chain, we will detail the algorithmic methodologies underlying the decision-making process of these contracts and we will outline the wider socio-economic perspectives opened by our approach.

EXISTING SYSTEM
Alharby and Van Moorsel [15] found four issues that might face developers when writing smart contracts: i) the difficulty of writing correct contracts; ii) the inability to modify or terminate contracts; iii) the lack of support to identify under optimized contracts, and finally; iv) the complexity of SC programming languages.Subsequently, Zou et al. [16] conducted an empirical study to explore the potential challenges faced by developers during SC development, with a focus on Ethereum block chain.The survey results revealed several major challenges.In particular, existing tools for SC development are still very basic.Programming SCs is different than programming in standard programming languages because the block chain and the code residing there cannot be changed after it has been deployed.Rocha and Ducasse [17] presented a general proposal for extending existing software modeling notations to include specific block chain concepts or integrations.According to these authors, modeling is an important part of designing software and in their preliminary work, they start the discussion on specialized modeling notations for dApps.The authors show three complementary modeling notations based on wellknown software engineering models: entity-relationship model (ERM), unified modeling language (UML), and business process model and notation (BPMN).Then they apply them to an example of block chain-oriented software (BOS) that implements part of the business logic in the block chain by using SCs.

PROPOSED SYSTEM
To summarize, we propose a novel approach for customizing and composing general Ethereumbased smart contracts (SCs) designed for the agri-food industrial domain in a simple way to be able to reuse the code and modules and automate the process to shorten the time of development, keeping its secure and trusted.As far as we know, this is the first attempt to develop a semi-automatic configurable system that supports the entire class of supply chains for the agri-food industrial domain.Though the approach is targeted to the agri-food domain, it can be easily extended to many other types of supply chains, where a product, a service, or a shipment is delivered by assembling and working on parts, and/or passes through different types of transformations and state changes.The study and development of an increased and improved general representation of food production specifically targeted to field traceability systems using block chain technology; The development of a set of modules, both general SCs and UI applications, able to be easily configured to generate a system for tracking real agri-food supply chains; The SCs were also checked for security and gas-saving; The development of a structured way, starting from the definition of the food production process through predefined tables, to configure these modules and to easily generate the final system also by developers with only limited knowledge of block chain technology; The development of a novel case study (honey production) to show how the approach works.

USER
Buys the target good from Retailers.S/he is usually not provided with an address.Users Buying agri products and the services from warehouse who sell agri products online and performs the following operations My Profile, Search Agri Products, Create Account, My Account Details, View All Purchased Agri Products.

WAREHOUSE
Warehouse have sought to sell their products to people who surf online.Before people buy anything online, get to know the seller people need to know their contact details for a reputable business should make this information easy to find.And also track the product details of customer mostly like, number of users view the product or purchase the product.A reputable business should also have good customer feedback -friends, family or other customers rate them highly and perform some operations like Add Products, View All Agri Products, View Purchased Products.Warehouse receives, stores, and sends goods.It is able to take ownership of the tokens associated with the target good, or simply to register their storage, leaving the ownership to the original one.

ADMIN
Administers the software system by managing and controlling the reading and writing access to the system by other actors and their permissions.This is a role present in most business process management systems.Admin will authorize users and Warehouse seller and performs the following operations such as

CONCLUSION
Nowadays, consumers worldwide want to be sure that the food they eat is safe and can be reliably traced back to its point of origin to give assurance that what they are buying is authentic and healthy.For this reason, they are demanding the highest standards of food safety throughout the supply chain and they are willing to pay for the intangible attributes of secure traceability and country of origin labeling.Traceability systems are considered important to ensure the safety of a food product and prevent food fraud in the food supply chain.It is essential to improve the current traceability systems, as unscrupulous producers could exploit the gaps in the systems to their advantage and to the detriment of consumers.Systems based on block chain technology and smart contracts, integrated with the Internet of Things, allow to implement a traceability system where the producers can share the responsibility to contribute information to their products, and independent third parts can identify themselves and certify the correctness of the data related to products' origin and quality.In this way, the customer can be assured of the truthfulness of the reported information with a high degree of confidence.In this context, we proposed a system enabling developers to quickly and smoothly develop traceability systems in the agri-food domain, without the need to grasp in every detail the technicalities of SC development, which is clearly different from classical software development.To this purpose, we accurately represented the problem domain, which was found suitable for such an approach, and developed a system able to automatically generate both the SCs and the UI of a tracing system.
Our approach starts from the description of the supply chain to be traced in terms of actors, producers, resources and products, events, and data.This description is given using a set of spreadsheet pages, which is a tool very easy to use also by people expert in the domain, but not in computer science.From these pages, converted to.csv les, the SCs are generated, as well as the HTML5 pages able to interact with them and providing the UI of the dApp.This methodology can be used at every node of the supply chain and can capture critical events, which are subsequently recorded immutably.Also, the actors who registered the events can be identified with a very high degree of certainty.In this way, the certification of every step of the production process is not only made by the producer itself as it is in traditional systems but can be audited by trusted third parties, which gives a much higher degree of trust that the information on the product is correct.

Journal of Creative Research Thoughts (IJCRT) c389
View All Users and Authorize, Add Category, View All Agri Products Categories, View All Agri Products, View All Agri Products by Block chain, View All Purchased Agri Products by Block chain, View All Agri Products Price Results, View All Purchased Agri Products Price Results.