---
# System prepended metadata

title: Decentralized and accountable farming using blockchain technology.

---

:construction: :construction: **Working Progress** :construction: :construction: 
# Decentralized and accountable farming using blockchain technology. 

<p style="text-align: center;"><b>Edwin Lomolo</b></p>

<p style="text-align: center;"><b>edwinmoses535@gmail.com</b></p>



**Abstract.** 

Food is a fundamental component in human lives; food that is grown in an environmentally sustainable way and socially just way, nourishes our bodies and builds culture and community. Recently, governments, institutions, and consumers have been concerned about the wide use of pesticides and fertilizers in our fruits and vegetables, which pose a health risk to human life. The food supply chain is composed of farmers, distributors, packagers, retailers, consumers, etc., rendering the chain more complex and sensitive. Additionally, complexity in the food supply chain often causes lack of transparency and traceability of the agriproducts. Recently, studies focusing on the application of blockchain technology to create trustworthy food supply chains have implored. The studies highlights implementation challenges of such solutions using blockchain technology and future prospects of the application of blockchain technology in the food supply chain. In this paper, we discuss previous studies on food traceability systems and propose a practical solution to creating trustworthy food supply chain using smart contracts on the Ethereum blockchain. 

**1. Introduction**

The large number of stakeholders involved in agriculture supply chain adds more complexity to the food chain, often causing lack of transparency and traceability of the agriproducts. Nowadays, consumer tend to spend more money on agriproducts whose origin is certified, which hinders achieving food security and food safety in the public health. 

Existing systems tackling food provenance tend to be centralized, untrustworthy, unreliable, and do not support composability. Considering the limitation of existing legacy system, together with emerging novel innovations, we see a new approach to tackling food provenance, achieve food security, and eradicate poverty in food accessibility. 

According to Demestichas et al., a food traceability system addresses a wide range of issues, including food fraud, food security and withdrawal, societal issues and consumer awareness. As the complexity of the food supply chain keeps growing, simultaneously, consumer needs and awareness for fresh, safe, and quality food are growing, thereby, a traceability system should be transparent and reliable. 

**2. Tokenization**

*2.1 Traditional tokenization*

The term *tokenization* can be traced from the 1970s, whereby, traditional finance companies implemented tokenization to protect confidential information; data security. Data tokenization mechanisms isn't just limited to financial information. For example, software application developers can create programs that utilize a token to keep login credentials secure; authentication and control access around the program; authorization. A string of non-sensitive letters and numbers effectively replaces your sensitive information such as email address. 

However, the above described token has an expiration time encoded into the token, whereby, its use case is only limited to a certain moment in the future. Thus, access privileges to your own personal information can be revoked; losing control of your personal identifiable information. Moreover, traditional tokenization as a data security layer is not guaranteed as an attacker can snoop in on the client-facing application and sniff out the authentication or authorization token and decode the token, thereby, concealing personal identifiable information.  Therefore, traditional tokenization mechanism don't guarantee data confidentiality and data ownership due to their centralized architecture. 

*2.2 Blockchain tokenization*

The world of computation is advancing rapidly, whereby, the digital world can be merged with our biological and physical world and communicate asynchronously. Blockchain tokenization can therefore be defined as the activity of converting physical and non-physical assets or objects into digital tokens. Real estate, land, art work, stocks, event tickets - these are just some of the assets belonging to traditional industries and are being tokenized on the blockchain. Traditional tokenization is slightly different from blockchain tokenization because the former revolves around data and the latter focuses on assets and ownership.

There are two major and community approved asset tokenization standards on the blockchain; [ERC-20](https://ethereum.org/en/developers/docs/standards/tokens/erc-20/) and [ERC-721](https://ethereum.org/en/developers/docs/standards/tokens/erc-721/). ERC-20 standard defines a minimal interface on how a class of fungible tokens known as ERC-20 can be build and highlights transfer mechanisms between parties. Due to their fungible nature, these tokens can be traded for anything. ERC-721 standard defines a minimal interface on how a class of non-fungible and unique tokens known as ERC-721 can be build and highlights transfer mechanisms between parties. However, due to their unique and non-fungible nature, these tokens cannot be traded for anything and have the ability to become different from each other, thereby, achieving distinguishable traits. 

With ERC-721 standard in consideration, physical object on earth that are unique in properties can be tokenized on the blockchain. Data appended to the blockchain inherits properties such as immutability, transparency, and ownership. A smart contract can tokenize farm-lands and afterward issue a unique token ID that can be traced to achieve food provenance or land ownership, whereby, its a registry of unique farm-land with distinguishable food production rate every season. 

```
def tokenize(token_id):
    if (exists(token_id)):
        raise 'Farm already exists'
```

The standard can be supplemented further with functions to manage farm during the season and also know the state of the farm. 

```
State { DORMANT, PREPARATION, PLANTING, GROWTH, HARVESTING, MARKETING }
```

Supplement function example:

```
def get_farm_state(token_id) -> str:
    # Is the token ID valid?
    if (exists(token_id)):
        return resolve_state(token_id)
    raise 'Invalid token ID'
```

Blockchain tokenization presents liquid mechanisms when integrated with existing legacy systems, thereby, unlocking a new ownership economy. 

**3. Seasonal data collection protocols**

An ideal agriculture traceability system should house information about each and every ingredient of the final harvest product. Information such as food origin, seeds used and its origin, fertilizer used at various stages and its origin, pesticide used and its origin, processing as well as distribution and storage conditions must be housed in the traceability system (Demestichas et al., 2020). Discussion around a reliable and effective agriculture traceability system resolves to a system that delivers both qualitative and quantitative information about the final harvest product and its origin. 

*3.1 Data collection*

This paper discusses traceability from *farm* to *fork*, whereby, previously we discuss how farm-land tokenization can prove food origin. Additionally, ERC-721 interface can be supplemented with functionalities to account not only for the state of the farm but also the confirmation of what happened during a specific state. Demestichas et al., raises some critical questions about the ownership of the data collected, what data is/should be collected, and how the data collected should be managed and be made available to both the stakeholders and consumers. 

According to Demestichas et al., a qualitative and quantitative traceability system should prove not only food origin but also the ingredients used in making the final harvest product. Considering this trait, we can model out mechanisms for collecting ingredients used in making the final harvest product, whereby, a farmer can proceed to the next state after confirming previous state or nonetheless. 

```
def confirm_planting(token_id, seeds_used, seeds_supplier, proof_of_supplier):
    if (get_farm_state(token_id) == PLANTING):
        continue
    raise 'State is not planting'
```

Data collection mechanisms must involve both mandatory traceability trait and voluntary traceability trait from stakeholders involved in the food supply chain, thus, creating a complete traceability information. The system should be trivial, whereby, farmers can pick their service providers(provide farm-inputs) for a season or a service provider can bootstrap a farm season by providing farm inputs. 

*3.2 Data ownership*

Blockchain technologies, especially public blockchains, entrusts every user on the platform a root role. Users of the platform are guaranteed of ownership and confidentiality of their assets and data once persisted on public blockchains. Technical publications on how to implement a transparent and reliable traceability system choose public networks due to adhering to open access to everyone. 

Supplementary functions in ERC-721 interface only allow the owner or an approved service provider on the farm to be accountable and update the state of the farm from time to time. Every action, state changes, and data input can only take place if approved by the owner of the farm, thereby, farmers can account for seasonal events and seasonal data of their farms. Farmer's can approve/disapprove service provider for a certain season, whereby, service providers can integrate their services to participate in the new agri-informational economy. Additionally, a service provider can choose the type of data to be used in the harvest product traceability without revealing much data, thus, not disrupting service providers' standards in maintaining and tracking product information. 

```
def confirm_planting(token_id, seeds, seeds_supplier, proof_of_supplier):
    if (get_owner(token_id) == caller or is_approved_service_provider(caller)):
        if (get_farm_state(token_id) == PLANTING):
            continue
        raise 'State is not planting'
    raise 'Restricted to farm owner or approved third party only'
```

Therefore, farmers or service provider can join, read and/or write data to the blockchain without losing access, and be accountable for their own actions. Additionally, reputation systems can be designed for every farm and service provider from the above concept, thus, the public can see which farm is live, which farm is dormant, and how liveness and productive is a farm. 

*3.3 Data authenticity*

Blockchain technology provides the mechanism to store and manage data in a secure way, whereby, every data point persisted on the blockchain inherits properties such as immutability. Tokenized farms on the blockchain can provide data which can be transformed further to develop insights and open up the farms to smart farming methodologies and smart index-based agriculture insurance. 

However, further research is required on the part of the farmer and transacting parties to provide genuine and precise information because seasonal information about seasonal processes and activities is scattered and owned by individual farmers. Therefore, technologies bridging off-chain or external legacy systems to on-chain or blockchain systems such as [chainlink](https://chain.link/) should be employed and integrated. Approved service providers can choose the data to sell to smart contracts running on top of blockchains by running an oracle node which provides seasonal data API for a farm. Therefore, enterprises and stakeholders in the agriculture supply chain benefits from such data economy by earning additional revenue by selling seasonal data to blockchain markets. 

According to World Economic Forum, by adopting a decentralized network of oracles with access to authenticated data sources, data authenticity is guaranteed by validating the integrity of the data input and providing highly available, tamperproof data exchange mechanisms. Enterprises and government institutions can join or contribute to a large open source community building a common interoperable infrastructure, thus, building across and interacting with counterparties operating in any blockchain infrastructure. 

**4. Traceability**

Earlier solutions for a traceability system, as discussed in previous technical publications, majority were conducted either in a manual or semiautomatic way. This method inconvenienced small-scale farmers but was convenient for large-scale farmers. Obtaining data about a harvest product from the complex agricultural supply chain became expensive and time-consuming. In this paper, we provide an overview on the use of RFID tags in traceability and discussing QR codes as a symbiotic and effective means to cut cost in traceability and promote transparency in the food chain. 

Electronic traceability system discussed above was based on RFID tags attached on products in a warehouse. According to Demestichas et al., the system was made up of RFID tags for reading product's attributes, RFID readers to obtain information from the tags, personal digital assistant (PDA) devices for the personnel, so they could read the RFID readers and store the information in a central computing system with a central database. However, depending on the type of tag, data can modified or deleted, thereby, breaking the trust in the supply chain. Also, consumers can only scan the product using the RFID readers provided by the reseller and/or retailers. 

In this paper, we propose QR - quick response code, attached on the final harvest product(s), whereby, consumers using a smartphone can scan the code from the web or a mobile app and view all the information about the product. This will cut cost in tracing vegetables across the supply chain, thus, not only create transparency in the food supply chain but also create trustworthy food supply chain. The QR code will be encoded with a hash which represents current farm seasonal data or farm seasonal data at a specific time in the past. 

```
# Hash season data(generate QR code image with resulting data hash value)
def hash_season(token_id, season):
    if (exists(token_id)):
        if (get_owner(token_id) == caller or is_approved_service_provider(caller)):
            if (get_farm_state(token_id) == HARVESTING):
                hash(season)
            raise 'Should hash season data after harvest confirmation'
        raise 'Unauthorized'
    raise 'Invalid token ID'

# Decode season data hash(from encoded QR code)
def get_season_data(hash) -> Season:
    if (hash_is_resolved(hash)):
        return resolve(hash)
    raise 'Invalid trace ID'
```

By presenting a QR code on the products, consumer trust in the agricultural supply chain may increase, resulting to a more symbiotic relationship between the farmer and the consumer and stakeholders. 

**5. Future Work**

***5.1 Composability***

Smart contracts executing on public blockchains can be thought as public open APIs, whereby, the state of an already deployed smart contract can be queried. For example, farms can participate in crop insurance markets built on blockchains without much overhead costs and guaranteed that claims will be settled autonomously, therefore, promoting inclusive finance to small-scale farmers. Startups and other organizations can build their business logic layers that extends from already deployed smart contract interfaces. 

```
External contract
interface IEFRMRegistry {
	def exists(token_id) -> bool: view
	def farmState(token_id) -> str: view
	def getOwner(token_id) -> str: view
	def approvedProvider(caller) -> bool: view
}

def create_market_for_farm(token_id):
	if (IEFRMRegistry.exists(token_id)):
		if (IEFRMRegistry.farmState(token_id) == HARVESTING):
			if (IEFRMRegistry.getOwner(token_id) == caller or IEFRMRegistry.approvedProvider(caller) == True):
				continue
			raise 'Only owner or approved service provider can go to market'
		raise 'Farm state is not HARVESTING'
	raise 'Invalid token ID'
```

*5.1.1 Decentralized markets*

Xiong et al., clearly articulates the limitation of blockchain application in e-commerce especially trading of agricultural products. Further, the application of blockchain technology in e-commerce is still in its infancy and the current case cannot prove the authenticity of crop information upload process to the blockchain prior to go-to-market strategy. In the above described system, the above limitation can be overridden by adopting  decentralized oracles ingesting data from trusted data sources, thereby, reconstructing trust in agricultural products. Markets can be extended to include distributors market, storage market etc, whereby, farmers can buy service from service providers securely without middlemen. 

*5.1.2 Smart farming*

Seasonal data collected for every farm and all natural resources that supports farming can be utilized in intelligent systems to provide insights on how to practice safe and sustainable farming. Xiong et al., proposes a comprehensive and secure system that facilitate the store, use, and management of agricultural data. The system should serve to store data generated throughout the entire value-added process from various actors and stakeholders immutably and transparently. Therefore, the system should reduce cost and risk, save time, and increase trust and transparency. 

**References**

[1] Demestichas, K., Peppes, N., Alexakis, T., & Adamopoulou, E. (2020). Blockchain in Agriculture Traceability Systems: A Review. *Applied Sciences*, *10*(12), 4113. 

[2] ERC-721. (2020). Retrieved 15 December 2020, from http://erc721.org/ 

[3] ERC-20 Token Standard | ethereum.org. (2020). Retrieved 15 December 2020, from https://ethereum.org/en/developers/docs/standards/tokens/erc-20/ 

[4] Xiong, H., Dalhaus, T., Wang, P., & Huang, J. (2020). Blockchain Technology for Agriculture: Applications and Rationale. *Frontiers In Blockchain*, *3*. 

[5] World Economic Forum. (2020). Retrieved 18 December 2020, from http://www3.weforum.org/docs/WEF_Interoperability_C4IR_Smart_Contracts_Project_2020.pdf