1 Introduction

In recent years, the global urban population has experienced rapid growth, rising from 751 million in 1950 to 4.2 billion in 2018 [1]. According to the United Nations department of economic and social affairs (DESA), the urban population covers around 55% of the world’s population, which is projected to reach 68% by 2050 [2]. The majority of cities around the globe are facing severe challenges in coping with rapid urbanization. Moreover, the impact of the COVID-19 pandemic has further aggravated the issue. To overcome these challenges, it is necessary to make cities sustainable through better utilization of emerging technologies such as IoT, cloud computing, and others. Modern technologies provide efficient decision-making tools to enhance the efficiency of planning, monitoring, and controlling resource consumption. Cities that use the technologies mentioned above are known as “Smart Cities.” Smart cities not only improve the quality of life but also optimally utilize resources, safeguarding the environment [3]. In smart cities, IoT platforms are used to monitor and manage city infrastructure such as traffic flow, parking, water distribution, waste disposal and treatment, air quality, etc., leading to improved public welfare, economy, government services, and urban planning. The smart cities market was valued at USD 739.78 billion in 2020 and is expected to reach USD 2036.10 billion by 2026 [4]. Well managed smart cities offer significant opportunities for economic development and greater access to essential services, including health care and education.

A smart city ecosystem comprises smart healthcare, smart banking, and smart transportation, which are interconnected, instrumented, intelligent, and sustainable [5]. Such an increase in living standards has elevated people’s concerns about the quality, hygiene, and source of food. Nowadays, food and hygiene sources are a major concern for people around the globe. WHO also presented statistics that food from unhygienic sources can adversely affect the health of millions of people. As per statistics presented by WHO, an estimated 600 million people, almost 1 in 10 in the world, fall ill every year by eating contaminated food [6]. In the past, many food scandals has happened all over the world. There was a horse meat scandal in parts of Europe in 2013, where lamb meat was replaced by horse meat [7]. Some other notable food-related scandals and hazards are the Salmonella outbreak caused by papayas [8], Escherichia coli caused by eating baby spinach [9], and Norovirus outbreak linked to raw oysters from British Columbia [10]. The WHO states that USD 110 billion is lost each year as a result of the production costs and medical expenses resulting from unsafe food [6]. Hence, an efficient food traceability system can not only enhance food safety but also reduce the financial loss incurred in an outbreak. It justifies the current research direction toward food traceability in smart cities and the corporate interest in the field. To guarantee food safety, it is necessary to build a complete system that can trace and track every component in food production. In literature, a few efficient food traceability systems have been presented.

Fig. 1
figure 1

Traceability of raw materials

Alfian et al. introduced IoT-based perishable food traceability systems that employ RFID for shipment tracking [11]. A similar IoT-based system has been presented by González-Amarillo et al. [12] to trace the crop traceability. The literature illustrates how the utilization of IoT devices such as RFID and QR codes has improved the quality of data flow in the supply chain. However, IoT-based food traceability systems are riddled with the issue of data integrity, trust, authenticity, and security. Moreover, with IoT devices having limited computing power and storage capacity, tracing food sources and batches becomes time-consuming. To address the same, Michelin et al. [13] presented an efficient approach based on blockchain. A blockchain is a distributed immutable ledger that stores data as continuous chains of blocks in a decentralized network. Blocks are interlinked with the cryptographic hash value. Blockchain provides seamless authentication, privacy, security, transparency, and trustworthiness. Besides, it also reduces the computational overhead of resource-constrained IoT devices. Furthermore, for leveraging smart contracts and decentralized applications, blockchain provides more autonomy to the smart traceability system. Several blockchain smart traceability systems have been presented in the literature. The majority of proposed solutions are just conceptual. Casino et al. [14], Hasan et al. [15], and Shahid et al. [16] among many others, presented a traceability system based on the Ethereum blockchain platform [17]. However, the Ethereum blockchain platform is unsuitable for a food traceability solution as it employs proof-of-work as the consensus mechanism [18]. Therefore, to implement a food traceability system, a novel platform based on the hyperledger sawtooth has been used [19]. The versatility of Hyperledger allows to use different consensus mechanisms, thus discrediting the main disadvantage of the Ethereum blockchain. Hyperledger’s versatility enables the use of various consensus mechanisms, thus negating the main drawbacks of the Ethereum blockchain. Employing hyperledger sawtooth enhances the food traceability system. However, it still lacks some key functionalities, such as the mechanism for role-based permission management and determining the payee of a transaction cost. Therefore, this paper proposes an EOSIO-based food traceability system to address the same. The main objective of the proposed food traceability system is to identify the raw material used in a product, as shown in Fig. 1. It can be observed from the figure that raw materials used in Burger are wheat, tomato, and chicken. The following contributions are made in this work.

  • A novel food-traceability model has been introduced for smart cities using blockchain and IoT.

  • The proposed system leverages the strengths of the EOSIO platform, providing an enhanced food traceability solution with an in-built authentication and authorization mechanism and optimal resource utilization.

  • The performance of the proposed system is validated in terms of resource utilization, CPU, and net bandwidth (NET).

  • The proposed EOSIO-based system is also compared with the Ethereum-based traceability system in terms of consensus algorithm, throughput, scalability, block confirmation time, latency, and block production rate.

The rest of the paper is organized as follows. Section 2 expands upon the technologies used. Section 3 discusses the related works and existing implementations. Section 4 introduces the proposed layered architecture for food traceability in the smart city. Section 5 illustrates the implementations of the proposed layered architecture along with the evaluation parameters. Section 6 summarises the work and describes the limitations of the proposed solution. Besides, it also highlights the future direction of the research.

2 Technologies Used

2.1 Blockchain

Blockchain is a distributed ledger based on a decentralized peer-to-peer (P2P) network that is both immutable and transparent in nature [20]. In blockchain, distributed ledger is arranged as chains of blocks, where each block is linked to the previous block by its cryptographic hash [21]. Each block has a block number and a time-stamp. Inside each block, multiple transactions are arranged as a Merkle tree. Each transaction is cryptographically signed using an asymmetric digital key. The consensus on maintaining the distributed ledger is defined by a governance mechanism referred to as the consensus algorithm. Blockchain technology was first presented in a white paper by Satoshi Nakamoto in 2008 [22]. The first programmable public permissionless blockchains blockchain was introduced by Vitalik Buterin in 2013 [23]. The public permissionless blockchains are categorized into Bitcoin and Ethereum blockchain networks. This categorization is based on read-write access to the blockchain and on participation in the consensus of a blockchain network. Public blockchains are open to all, i.e., anyone can view the ledger. while, in a private blockchain, only select members can view the ledger. A permissionless blockchain allows anyone to perform transactions and participate in the consensus, and a permission-based blockchain allows only select members to do the same. Permissioned blockchain lies under a single organization. There is another blockchain technology named “Consortium Blockchain,” which is similar to the permissioned blockchain, except it is controlled by a collection of organizations rather than a single organization [24]. Hence, in Consortium blockchain, a specific pre-defined set of members is only allowed to make transactions and perform consensus. To encode the blockchain data efficiently and securely, a Merkle Tree is used. Besides, consensus algorithms are also used to achieve synchronization and reach an agreement between the thousands of nodes on a blockchain network. The following sections discuss Merkle trees and the consensus algorithm.

2.2 Merkle Tree

A Merkle tree is used to enhance the immutability of the blockchain [25]. A Merkle tree adds up all of the transactions in a block and provides a digital fingerprint of the complete set of operations, allowing the user to check whether the block contains any transactions. A Merkle tree is a binary tree in which the leaf is each node’s hash, i.e., the block’s hash in a transaction, while each non-leaf node is the hash of a combination of its corresponding child nodes [26]. Further, the root of the Merkel tree is used to verify the data on a Merkle tree. A Merkle root is a straightforward mathematical method for validating the data on a Merkle tree. Merkle roots are used in cryptocurrency to ensure that data blocks sent between peers on a peer-to-peer network are complete, undamaged, and undamaged.

2.3 Consensus Algorithm

The consensus algorithm defines how to maintain the distributed ledger [27]. In a blockchain, no centralized authority verifies transactions or blocks. So, to reach an agreement on any single block, we require a consensus algorithm that is accepted across the entire blockchain. In the literature, various types of consensus algorithms, as discussed below, are presented and implemented [28].

  1. 1.

    Proof-of-Work: Proof-of-Work (PoW) is a consensus algorithm that enforces the peers in the blockchain network to solve a hard mathematical problem [29]. PoW is used in Bitcoin as well as Ethereum. In PoW, peers that compete with each other to solve the problem and mine the block is termed, miners. They receive a reward according to the resource consumed. Blockchain validators in a PoW system must continuously pass data from a block header through a cryptographic hash function. Every time the input data is passed through the cryptographic hash function, validators add an arbitrary number called a nonce. To decide what data is added to the next block in a blockchain, PoW requires a lot of electricity and processing power. The PoW technique requires specialized computers known as ASICs to solve complicated mathematical problems. This leads to high financial costs and ecological damage [30].

  2. 2.

    Proof-of-Stake: Proof-of-Stake (PoS) consensus algorithm was developed as an alternative to PoW in 2011 [31]. Although the objectives of PoS and PoW are comparable, there are several significant distinctions between them, especially when validating new blocks on the blockchain network. The Proof of Stake (PoS) consensus algorithm validates blocks based on stakes held by network participants. In PoS, each block’s validator is selected randomly from the stakeholders depending on the available computing power. Although each PoS system may execute the algorithm differently, the blockchain is generally safeguarded by a pseudo-random election process that considers a node’s allocation. The allocation evaluates the party’s commitment to ensuring the network. To boost the network’s scalability and avoid excessive electricity waste, the Ethereum blockchain, the world’s largest blockchain network in developer activity, has migrated from the PoW algorithm to the PoS algorithm [31].

2.3.1 Delegated-Proof-of-Stake

An improved PoS method that tries to address the flaws of both PoW and PoS consensus algorithms is called Delegated-Proof-of-Stake [32]. The DPoS consensus algorithm is a democratic mechanism where a few nodes have delegated the responsibility for generating and validating new blocks [33]. This is done by a voting mechanism where each party’s voting power is proportional to the token staked in the system. Since the reputation of the delegated nodes influences the voting, misbehavior will lead to being expelled and replaced. DPoS is more scalable than PoS and PoW and can provide more transactions per second. The EOSIO blockchain employs a DPoS consensus mechanism.

2.3.2 Smart Contracts

Smart contracts are programs generally deployed on the blockchain and run when some specific criteria are met [34]. Smart contracts are used to implement the business logic on a blockchain network. A smart contract has a unique address and is visible to all nodes in the blockchain network once it is deployed. Utilizing this address will activate blockchain smart contract features [35]. Ethereum requires the use of the Solidity programming language to write smart contracts [36]. Once compiled, the byte code of the smart contract is generated and runs on the Ethereum Virtual Machine. EOSIO supports multiple programming languages to write smart contracts, including C++, Rust, Go, etc. They are compiled into Web Assembly (WASM), which runs on the EOSIO blockchain network [37].

2.4 Ethereum Blockchain

Ethereum is an open-source, public blockchain network. In the Ethereum environment, everyone agrees on the state of a Ethereum virtual machine (EVM) [38]. Every node in the blockchain network maintains a copy of the EVM state. When a transaction request is made, all the nodes validate and carry out the request, which subsequently updates the EVM states of all the nodes. Ether (ETH) is the default token/cryptocurrency used on the Ethereum main network. Ether also makes it easier to validate transactions and incentivizes nodes to contribute computational resources to the network [39]. An additional Ether for a transaction is given to achieve the same. The incentive paid corresponds to the time required to complete the computation. Ethereum supports smart contracts. Anyone with enough Ether can deploy smart contracts to the Ethereum main network because it is a public permissionless network. Ethereum supports Solidity and Vyper programming languages for writing smart contracts. The interactions made with the smart contract are final and cannot be reversed. Ethereum employs proof-of-work as the consensus algorithm. PoW has very high and unsustainable energy consumption.

2.5 EOSIO Blockchain

EOSIO is an open-source blockchain platform. It was created in 2018 and is maintained by Block One [40]. EOSIO blockchain networks supports high performant decentralised applications. C++ is used to write EOSIO smart contracts [41]. NodeOs, cleOs, keosd, EOSIO.CDT and system contracts make up the core layer of the EOSIO blockchain. In an EOSIO blockchain, smart contracts can be updated to customize resource allocation and governance rules. A WebAssemby virtual machine (WASM) serves the functionality of the smart contract in EOSIO [42]. The core components of EOSIO are explained as follows.

  • Nodeos (Node + EOSIO): NodeOs is the node daemon in EOSIO that enables a user to run a single-node blockchain network with a local development platform and API endpoints. The nodeOs configuration file can be tweaked to allow or disable EOSIO features.

  • Cleos (CLI + EOSIO): Cleos is the command-line tool used to interact with nodeOs and is used to deploy EOSIO smart contracts, invoke actions, and interact with keosd.

  • Keosd: Keosd is the key management daemon in EOSIO. It is used to store private keys securely and sign transactions and digital messages.

  • EOSIO.CDT: EOSIO.CDT is a tool that supports building smart contracts. It helps to generate optimized WebAssemby (WASM) files with library support that can be deployed in the EOSIO blockchain.

The EOSIO platform emloys DPoS as the consensus algorithm. DPoS allows to select block producers through a continuous approval voting system, provided that one holds sufficient tokens [43]. When tokens are staked for CPU and NET, system resources are assigned proportionally to the percentage of tokens staked for the same resource at the same moment, regardless of market fluctuations. Establishing the smart system contract allows system resources to be dynamically allotted to EOSIO accounts. The following is a list of system resources in an EOSIO blockchain.

  • RAM: In the EOSIO blockchain network, RAM is one of the core system resources. Blockchain accounts, permissions, smart contracts, and other data are kept in RAM for quick access. It is a long-term storage solution that must be purchased. As RAM is a restricted persistent resource, the EOSIO staking mechanism does not apply to it.

  • CPU: It is processing time that is measured in microseconds (\(\mu\)s). The staking mechanism of EOSIO applies to the CPU, as it is a transient system resource.

  • Network (NET): It is the network bandwidth, measured in bytes. An EOSIO account is used to deploy actions to the blockchain. The staking mechanism of EOSIO applies to NET, as it is a transient system resource.

3 Related Works

Food traceability has always been considered a complex process. Throughout the food supply chain, a wide range of data collection nodes are present, each providing different types of data. Data in a food supply chain ranges from product life and transport information to environmental data. Establishing a good traceability system for such a problem has always been challenging. Therefore, traceability units are first identified before establishing a food traceability system. The food traceability system determines components before the model’s development. An efficient system should cover production, manufacturing, trade, and logistics. Moreover, reliable and accurate data must be recorded at each stage for better and more efficient traceability. Employing RFID in logistics and supply chains provides a systematic improvement to the food traceability systems. Dabbene et al. [44] employed RFID in monitoring critical steps of food distribution, improving visibility in the supply chain. A similar approach was proposed by Farooq et al. [45] to introduce a cost-effective solution for improving consumer health. The utilization of IoT technology for recording environmental data, product, and shipment details has improved food traceability systems. Moreover, IoT can be regarded as a critical component in digitizing the supply chain. Abdel-Basset et al. [46] introduced an IoT-based system that was able to establish a dynamic real-time business model with minimal human error. Recently, QR codes and IoT-based blockchain frameworks have also gained the attention of consumers to acquire traceability details [47, 48]. Alfian et al. [11] introduced a shipment and transport tracking system using RFID and smart sensors to monitor and control environmental variables. IoT devices have systematically improved food traceability systems due to their limited computing power and storage capacity. However, managing the trust, authenticity, integrity, and security in the IoT-based system is a challenging task [49]. Therefore, blockchain has been used to mitigate these limitations and improve the foundation of food supply chain management and traceability. Recently, the integration of Blockchain and IoT (BIoT)-based models has significantly received the attention of researchers [30]. Several theoretical frameworks for a BIoT-enabled food traceability system have been introduced in the literature [14, 50, 51]. However, the majority of the studies are limited to theoretical frameworks.

Recently, Walmart and IBM have jointly introduced a commercial BIoT model for food traceability [52]. Besides, some other BIoT-based models were also presented in the literature. Casino et al. [14] introduced an Ethereum-based BIoT model for traceability in the supply chain. However, the traceability units defined in the proposed model are batches. Hence, the model can only provide limited traceability in food safety. Hasan et al. [15] also introduced an Ethereum-based BIoT model for shipment tracking. Furthermore, Salah et al. [53] presented a traceability system based on the Ethereum platform. In the above model, Ethereum smart contracts are leveraged to track shipments, which sometimes fail to guarantee the authentication or authorization of the product. Therefore, Shahid et al. [16] presented an effective solution for traceability that ensures product authenticity. Food traceability solutions based on Ethereum are impractical for food traceability because Ethereum uses the PoW consensus mechanism, which is not suited for food safety. To mitigate the same, Tsang et al. [54] presented a model integrated with a consensus mechanism developed for supply chain management (SCM). BIoT models are also a trending research topic in other domains. Multiple papers have been published using the BIoT model in the medical field. Uddin et al.[55] presented a model for remote patient monitoring using the BIoT framework. In the literature, many BIoT-based healthcare frameworks have been presented. Liu et al. [56] introduced a smart BIoT traceability system for drugs. Besides, a secure Blockchain-enabled transportation system has also been presented. Although the proposed model addresses the issue of practical consensus algorithms, their practical use is impossible until a product is developed and published.

Moreover, the Hyperledger Sawtooth platform has also been used to implement a food traceability system [19, 57]. The sawtooth-based food traceability model attained better scalability and higher throughput. Although proven to be a better solution, Sawtooth lacks a permission management module, while other techniques cannot distinguish between the business logic and security modules. Considering the aforementioned limitations, an improved EOSIO-based layered architecture is designed and implemented in this paper. The proposed layered architecture decreases the security gaps and attack vectors. Further, to enhance the strengths of EOSIO, the novel BIoT-based food traceability model for the smart city has been implemented. Some of the significant enhancements to the EOSIO-based food traceability system include permission management modules, controls for payer scheduling of transactions, and a token-free blockchain. The Table 1 provides a compact summary of the related works and the proposed EOSIO-based layered architecture. Check marks in the table indicate that a model supports a particular transaction protocol. It can be observed from the table that there are double-check marks for authorization and authentication transaction protocols for the proposed, which means the proposed EOSIO model enhances both authorization and authentication. On the contrary, other models enhance either authorization or authentication.

Table 1 Comparison of proposed system with existing literature

4 Proposed Model

Integrating Blockchain and IoT (BIoT) has systematically enhanced food traceability systems by improving control over the supply chain. The BIoT traceability system offers better real-time dynamics and ensures significant improvements in auditability, accountability, immutability, efficiency, process quality, high availability, security, and fault-tolerance. In this paper, a BIoT-based layered architecture has been introduced for food traceability systems. The following section details the proposed layered architecture.

4.1 Proposed Layered Architecture for Food Traceability

Figure 2 presents the layered architecture of the proposed model. It consists of 5 layers, namely perception/IoT layer, management layer, blockchain layer, service layer, and user layer. All layers in the proposed architecture are logically connected. The functionality of each layer has been discussed in the following subsections.

Fig. 2
figure 2

Layered architecture of the proposed model

4.1.1 IoT/ Perception Layer

The perception layer is the lowest layer that encapsulates different IoT devices. Each of these devices is responsible for forwarding data to the management layer. The IoT devices include temperature, pressure, pH, and GPS sensors along with identification tools such as RFID, QR code, etc., for monitoring environmental variables. At this layer, data is constantly generated and forwarded to the next layer. The next layer then adds the received data to the blockchain at fixed intervals or in response to events.

4.1.2 Management Layer

The management layer acts as a bridge between the IoT and the blockchain layer. The functionality of this layer is to manage IoT devices. Besides, this layer is also responsible for the addition or removal (temporary/ permanent) of the IoT device, along with device authentication and authorization. Moreover, forwarding data to corresponding smart contract actions is another task of this layer.

4.1.3 Blockchain Layer

This layer consists of the distributed ledger, the consensus mechanism, smart contracts, miner nodes, and peer nodes. The distributed ledger in the blockchain is arranged as chains of blocks, where each block is linked to the previous block in the chain by its cryptographic hash. The consensus algorithm defines how to reach an agreement on any single block and thus maintain the distributed ledger. Smart contracts facilitate, verify, enforce a control sequence, and implement logic using code. Section 3 explains blockchain and its components in detail.

4.1.4 Application Layer

The primary function of the application (service layer) is to process the authorized user layer requests. In this layer, either a block is added to the blockchain network or data is retrieved. Smart contracts are used only to implement this layer, and user permissions are managed in the implementation.

4.1.5 User Layer

This layer consists of all stakeholders in the food supply chain. The stakeholders in the traceability system include farmers, suppliers, manufacturers, storage warehouses, retailers, consumers, and administrators. Each stakeholder tries to provide better service to the consumer. All stakeholders add data to the blockchain in line with their role. They are authenticated and authorized by the service layer based on their role. The administrator deploys the smart contract on the blockchain and is the smart contract owner. Furthermore, the administrator performs the addition or removal of users and IoT devices.

4.2 Key Components of the Architecture

Figure 3 represents the architecture of the proposed model with control flow between the key components. The major components of the proposed model are discussed below.

Fig. 3
figure 3

Architecture of proposed model

4.2.1 Traceability System

The first and most important stage in the food traceability system is to identify and define the traceability units. The traceability unit determines the extent to which the traceability system is detailed. Figure 3 depicts the components of the traceability units. The traceability units provide extensive and low-level information on the product’s raw material. Data at each stage of the supply chain is stored in the blockchain as traceability units. Each traceability unit contains information that serves as a primary key. The primary key is mapped to various additional data structures to enhance traceability. Other data, such as block timestamps is not used in tracing but is used to calculate product life, shelf life, and other metrics. The data flow model represented in the Fig. 4 demonstrates the workflow of the traceability system. The proposed traceability system first acquires details such as product ID, product name, and items involved in making the product. After that, each item is linked to its source to get the details of the raw materials used. Both Ethereum and the proposed EOSIO use the same traceability units mentioned above.

Fig. 4
figure 4

Data flow of the proposed model

4.2.2 User Identity Management

The primary goal of this study is to improve user identity management. For the same, actions and transactions are authorized with permissions associated with the account. Permissions are generally stored in an authority table along with the thresholds. The threshold is used to determine whether or not an action is approved. The proposed EOSIO supports hierarchical permissions in which any permission can be created and added at any time to the authorization table. The authority of the newly added permission will be equal to the authority of its parent. Account public key, account name, time wait, and permission level determine the authorization of accounts in EOSIO while Ethereum updates the smart contracts. The EOSIO permission management is a separate module from the business logic implementation. Hence, the complexity is reduced, and better layer separation is achieved.

4.2.3 IoT Device Identity Management

IoT device management involves verifying the devices’ identity and facilitating functions to be triggered by the corresponding devices. Verifying the identity of IoT devices is achieved in the same way as user authentication. Smart contract plays an essential role in maintaining IoT device identity. The administrator adds the addresses of IoT devices to the blockchain with a corresponding modifier to provide the necessary function. When these devices call the smart contract, they are first authenticated with the addresses, and after that, the usable function is provided.

5 Implementation and Experimental Analysis

A two-fold implementation and experimental analysis have been conducted to explore the relevant blockchain for food traceability. First, the proposed model is implemented using Ethereum and then enhanced using EOSIO. The detailed implementation steps of the Ethereum and the proposed EOSIO have been presented in Sect. 5.1 and 5.2. Further, the proposed EOSIO has been experimentally validated in sect. 5.3 in terms of execution cost, consensus algorithm, authentication, authorization, scalability, block-confirmation time, block production rate, and throughput.

5.1 Implementation Using Ethereum

This section discusses the implementation of the food traceability model using the Ethereum blockchain. In addition, it also detail how smart contracts are used to set up traceability systems and user management modules. Ethereum is a public, permissionless blockchain network. It utilizes the solidity programming language for developing smart contracts. The smart contracts are utilized to facilitate the food traceability system and the interactions between stakeholders. The smart contract is deployed and tested in two environments: Remix virtual machine [58], and Ropsten test network [59]. Remix is an online Ethereum platform that enables writing, compiling, deploying, running, and interacting with smart contracts. The Remix platform is used to deploy smart contracts on the Ethereum main network, different test networks, local machines, and a virtual machine (VM). VM is helpful in the initial phase of smart contract development. The Remix VM offers a variety of test accounts with synthetic Ethers, allowing users to test gas usage and optimize smart contracts without worrying about connectivity or mining. In the Ropsten test network, the working scenario of the food traceability system is simulated by deploying the smart contracts. The Ropsten test network is similar to the Ethereum main network in the currently available open-source test networks. Hence, the metrics obtained from the Ropsten networks are considered for evaluating the food traceability system using the Ethereum blockchain. The contract creation details using the Remix VM and Ropsten test network are depicted in Figs. 5 and 6 respectively. Further, the key attributes used in the Remix VM and Ropsten test network transaction information are listed below.

  • Status: Indicates the success or failure of transaction.

  • Block: Indicates the block number of transaction.

  • Timestamp: Provides the time of addition of block in the blockchain

  • From: The address of the user invoking the smart contract.

  • To: Address of the smart contract that uniquely identifies the contract in the blockchain network.

  • Gas Limit / Usage: the amount of gas allocated for the transaction to execute.

  • Transaction Fee: the amount of work performed to add a block in the blockchain.

  • Value: amount that is transferred in the transaction. This is only applicable if the smart contract functions are payable.

Fig. 5
figure 5

Transaction details of contract creation in remix virtual machine

Fig. 6
figure 6

Transaction details of contract creation in Ropsten test network

The Ethereum-based food traceability method uses the amount of gas allocated to measure the completed work. This approach provides a priority fee higher than the base price to prioritize and execute essential transactions. The same can be observed in Fig. 6. Moreover, the Table 2 provides the summary of the gas usage, block confirmation time, and transaction cost for the functions in the food traceability system. The values mentioned in the table are obtained using the Ropsten test network. The transaction fee is calculated by multiplying the sum of the gas price and priority fees with the gas usage. As the gas price is continually changing, repeating the same transaction may result in different transaction fees. The transaction cost in Table 2 is the weighted average of the values obtained in different runs.

Table 2 Ethereum transaction cost

The flow of the proposed Ethereum-based food traceability system has been presented in Fig. 7. Traceability functions are similar to those described in Fig. 4. First, the getProductDetails() function is used to get the product ID, product name, and item IDs of any particular item, and then to get the traceability details of any specific item, the getItemDetails() function is used. In the subsequent step, Harvest ID and Storage ID are used to obtain the raw materials used in the product.

Fig. 7
figure 7

Working of the traceability system

5.2 Proposed EOSIO Based Food Traceability Model

It has been observed from the literature that the EOSIO-based models show better efficacy than the Ethereum-based models. Therefore, EOSIO blockchain-based traceability [60] has been presented in this paper to enhance food traceability. The details of the EOSIO blockchain have been presented in Sect. 2.5. In the EOSIO blockchain, business logic is implemented on the blockchain by utilizing smart contracts. The proposed model utilizes EOSIO libraries defined in C++ to implement the food traceability system. A system with the following specifications has been used to implement the proposed food traceability model.

  • CPU: Intel i7

  • Memory: 16 GB

  • Disk: 128 GB NVMe SSD

For the proposed model, NVMe SSDs are recommended for higher disk read/write speeds. To implement the proposed approach, EOS Studio [61] and Docker [62] have been used, in which Docker provides an environment to run the EOSIO and EOS Studio provides the development environment. Moreover, with the help of EOS Studio and Docker, smart contracts can be built and deployed on local nodes, test networks, and the EOSIO main network. The local node supports both single-node and multiple node deployments and is also helpful in the initial smart contract development stage. Additionally, the EOS Studio are used as a contract inspector and network manager, allowing users to interact with deployed contracts and fetch the resource utilization metrics. EOSIO uses Delegated-Proof-of-Stake (DPoS) as the consensus mechanism. In DPoS, validators/producers are responsible for producing a block and are delegated by different stakeholders.

Fig. 8
figure 8

EOSIO input command for item data entry

Furthermore, Fig. 8 depicts the commands used in EOSIO to deploy and test smart contract actions. Cleos is the command-line tool that runs on every EOSIO node and is used to interface with nodeOs. The NodeOs is set up to handle smart contracts, validate transactions, generate blocks containing valid transactions, and confirm blocks before they are recorded on the blockchain. The –url indicates the http/https URL where nodeOs is running, while the push subcommand is used to push transactions to the blockchain. The smart contract actions in the adminn account are addharvest, addstorage, and additem. Further, producer1@active denotes that the active user has the needed permission key. The EOSIO blockchain provides a distinct layer of authentication and authorization for users. It can be claimed to be more secure because authentication and authorization are not required to be implemented individually. Moreover, Fig. 9 displays the multi-index table for the actions of the deployed data. Moreover, Fig. 9 displays the multi-index table for the actions of the deployed data. The multi-index table of the proposed EOSIO blockchain is similar to Ethereum’s multi-index table, which is used at a later stage for providing traceability.

Fig. 9
figure 9

EOSIO harvest data multi-index table

5.3 Experimental Analysis

This section presents the performance evaluation of the proposed layered architecture for food traceability. The following performance parameters have been considered for food traceability.

  • Variation in gas usage with increasing string length.

  • Transaction fee of the implementation

  • Gas usage of smart contract functions.

  • Block confirmation time.

  • Resource consumption.

Figure 10 depicts the relationship between gas usage and input string length in Ethereum. The plotted graph highlights that gas usage and input length are directly proportional. Hence, the use of strings in the blockchain should be limited. Further, costs for performing various transactions in Ethereum have been tabulated in Table 2. The transaction costs can be reduced if the private implementation of Ethereum is employed. Besides, table also highlights the block production time in Ethereum. The weighted average of all test results produces a 56-second block production time for Ethereum. The latency, throughput, and block production rate are affected by such a large block production time. Therefore, an improved EOSIO-based on DPoS implementation has been used in the proposed traceability system to enhance the latency, block production rate, scalability, and throughput. The improved EOSIO-based on DPoS implementation achieved block confirmation time in the range of 1 s. Other performance parameters such as throughput and block production rate have also improved. Moreover, the proposed EOSIO-based implementation is compared with the Ethereum-based implementation in Table 3 to validate the efficacy of the proposed approach. It can be observed from the table that the proposed traceability system outperforms the Ethereum-based food traceability system in terms of permission management, block production rate, throughput, and block confirmation rate. Additionally, in the EOSIO blockchain, the payer can be delegated for action in the smart contract. Such a configuration control allows the transactions to be independent of the monetary concept and further improves the practicality of EOSIO-based implementation. Additionally, the EOSIO permission management further improves the efficacy of the proposed approach.

Fig. 10
figure 10

String Length vs Gas Usage

Table 3 Comparison of Ethereum and EOSIO

Furthermore, the block confirmation time of the Ethereum and EOSIO-based traceability systems is compared in Fig. 11. It can be envisioned from the figure that the proposed EOSIO-based traceability system performs better than the Ethereum-based implementation. Besides, resource utilization of the proposed food traceability system has also been depicted in Fig. 12. It can be pertinent from the above analysis that the proposed EOSIO-based food traceability system is much superior to the Ethereum-based system.

Fig. 11
figure 11

Block confirmation time

Fig. 12
figure 12

EOSIO resource utilisation

6 Conclusion and Future Works

This paper introduced a Blockchain-IoT-based model using EOSIO to achieve a secure, transparent, immutable, and scalable food traceability system in smart cities, with inherent authentication and authorization features. The overall functionality of the proposed food traceability system can be detailed in three phases. The first phase identifies suitable traceability units to provide better transparency and traceability. After that, a layered architecture of the food traceability system is presented in the second phase to improve security. Further, layered architecture is implemented in the third phase using two blockchain platforms, Ethereum and EOSIO. Both implementations are extensively studied to identify the better-suited blockchain for food traceability systems. It has been identified from the analysis that the EOSIO-based traceability system is more suitable than Ethereum. The strengths of EOSIO allow for better implementation of the proposed model. With the role-based permission management in EOSIO, a more secure and practical food traceability system for smart cities has been developed. The framework implemented is a valuable road map for identifying the best-suited blockchain for food traceability, with many enterprise-ready blockchains available today. The implementation was also deployed in test networks to simulate the real-world scenario. As a future improvement, the implementation may be deployed in a real-world scenario and assessed on how well it can handle the complex food supply chain process.