1 Introduction

A supply chain is defined as the process of acquiring a product from its manufacturer and delivering it to the end-user (customer). A supply chain can be for any product, such as an automobile, clothing, medical supply chain, etc.Like other supply chains, the healthcare supply chain has many stakeholders, starting with the raw material supplier and progressing to the manufacturer, then a wholesaler and distributor, and finally the pharmacist and the customer (patient) [38]. When we examine healthcare supply chains, we see that they have a large and complex structure and numerous stakeholders. Traceability, transparency, dependability, cost efficiency, integrity, and sustainability are all lacking in earlier versions of supply chains that were not as digitally advanced. There is no proper method for tracking the history of medicine transitions and ownership from their origin to the patients. Due to a lack of traceability and transparency, there is uncertainty about the medicine’s originality and security, which leads to issues related to drug counterfeiting and falsification. In addition, the lack of these critical features leads to black-marketing of medicines, the intermediary falsifies the actual drugs and sells the irrelevant drugs at a lower price. These activities do not stop at lowering the prices of fake products; instead, black marketers raise the prices of original products to such an unpayable level that people in need are forced to switch to them. These actions not only cause a slew of health problems for the people, but they also result in a large number of casualties at times, which can cause panic among the people in times such as the Covid-19 pandemic.

According to Mike Seed (2021) [37], the covid-19 pandemic is a perfect storm of opportunities for counterfeiters to make a good reach of their falsified medicines in people’s urgent needs.And emphasized the importance of accepting a perfect methodology to deal with such activities. He stated that in March 2020, authorities from 90 countries came forward in an Interpol operation to take action against such activities, resulting in the seizure of illegal drugs and medicines worth $14 million. During the covid-19 Chinese authorities also seized over 3000 fake Covid-19 vaccines.

According to a BBC report published on April 26 by Vikash [29], the black market for important drugs and other medical goods has increased significantly. The drug prices have been raised by a factor of two, three, or even four. Even the oxygen cylinders were black marketed in New Delhi at a higher price than regular ones. The BBC only published the report after verifying the sources by contacting the product’s dealers as shown in Table 1.

Table 1 Price hike of essential medicines during Covid-19 [29]

When it comes to developing countries, these issues play a critical role of their own. According to a World Health Organization (WHO) [47] report, one out of every ten medical products in developing and low-income countries is subpar or falsified. Since 2013, WHO has received 1500 reports of falsified medical products, with 42% coming from the African region, 21% from the WHO Region of the Americas, and 21% from the European region. Aside from these, many cases go unreported, with only 8% of reports coming from the Western Pacific region and 2% coming from South East Asia.According to Dr. Mariângela Simo, WHO’s Assistant Director-General for Access to Medicines, “substandard or falsified medicines not only have a tragic impact on individual patients and their families, but they also pose a threat to antimicrobial resistance, adding to the worrying trend of medicines losing their ability to treat”.Substandard medical products reach patients when the tools and technical capacity to enforce quality standards in manufacturing, supply, and distribution are limited. Falsified products, on the other hand, tend to circulate where inadequate regulation and governance are compounded by unethical practices by wholesalers, distributors, retailers, and health care workers. According to the report, when the tools and technical capacity to enforce quality standards in manufacturing, supply, and distribution are limited, substandard medical products reach patients. Falsified products, on the other hand, are more likely to circulate in areas with inadequate regulation and governance, as well as unethical behaviors by wholesalers, distributors, retailers, and health care workers.

These data show that there is a critical need to adopt a technology that can help in coping with such actions. So,this paperproposes a method for implementing blockchain technology in the healthcare supply chain to prevent such activities.

1.1 About Blockchain technology

Blockchain is a distributed, immutable ledger [13, 30, 36]. It is a decentralized network of nodes in which each node communicates with the others via a peer-to-peer network. The shared information on the blockchain network is transparent and immutable, and only network members with permission can access it. Orders, payments, and other network transactions can all be tracked using blockchain technology. It also aids in cost reduction. Blockchain is a distributed ledger in which a transaction can only occur once, preventing record and transaction duplication. Once a transaction is completed on the network, it cannot be changed by anyone else on the network. If an error occurs in the transaction, a new transaction must be added to correct the error, and both transactions are then visible on the network. The network transaction is defined by a set of rules known as smart contracts [7]. Solidity is the programming language used to create smart contracts. Different variants of Blockchain networks are summarized in Table 2.

Table 2 Different types of blockchain networks

The paper presents a novel secure authentication scheme for dug delivery and management to provide security in permissioned and public environments. A QR-based authentication algorithm to perform transactions between buyer and seller is proposed. The work is novel, as it presents a transformative view of making the pharma supply chain more secure, robust, and reliable. Also, the paper investigates a very important aspect, the financial viability of this system for various kinds of transactions that are not available with other existing ones.

The rest of the paper is organized as follows: a detailed and state-of-the-art review of existing literature in the field is presented in Sect. 2. Proposed methodology is explained using the system’s high-level architecture diagram forms Sect. 3. Detailed discussion on the implementation along with algorithms used is included in Sect. 4. Testing and validation of the proposed approach are presented in Sect. 5. Obtained results and detailed discussions along with comparative analysis are presented in Sects. 6. Sect. 7 concludes the article and 8 sketches future work directions.

2 Literature review

Blockchain technology has received a great deal of attention recently since they provide decentralized approaches to the creation and management of valuable data and their allied transactions. In addition to the classical application of securing the drug supply chain mentioned in this paper, blockchains have also been used in a variety of domains like health care [6, 23, 31, 39, 42] insurance [32], secure banking [41], managing IoT authentication protocols [43], disaster management [35], smart city management [1, 5], Smart Logistics and Transportation [11], securing crowd funding [9], managing IIoT(Industrial Internet of Things) based infrastructure [22, 46], land registration management, Cyber-physical systems [27], Accident prevention [40], pet adoption [8] and many more.

The various research papers related to the blockchain in supply chain management are studied and their findings are mentioned below.

Arim Park and Huan Li (2021) [34], studied the role of blockchain technology to improve the sustainability of the supply chain. After reviewing various papers on the benefits of blockchain technology, they realized that blockchain technology, with its growing versatility, provides better traceability mechanisms, security, reliability, and cost-efficiency. They also stated that blockchain technology fulfils the three pillars of sustainability, notably environmental, social, and economic sustainability.According to them, the blockchain-enabled supply chain allows us to track the product’s location as well as the number of carbon emissions, wastewater emissions, and toxic releases from each step to avoid violating environmental policies. Improves resource management from raw material origin to avoid over-extraction of natural resources. It enables businesses to track their waste emissions to recycle and reuse waste, promoting environmental sustainability. They discovered that in a blockchain-enabled system, stakeholder information is immutable, and no one other than authorized actors can access it. As a transparent system encourages less corruption, it provides social sustainability. They discovered that smart contracts only allow transactions if all participants agree to them, resulting in information symmetry with a transparent system that promotes economic (governance)sustainability.Finally, they concluded that incorporating blockchain technology into supply chain management systems can significantly improve their sustainability.

Mueen Uddin et al.(2021) [45],investigated the use of blockchain in the pharmaceutical supply chain. In the paper, they listed two blockchain architectures that can be used to develop a system for improving chain traceability and security. However, while implementing the solution, they discovered some issues thatshould be kept in mind as work on this research. According to various studies based on this technology, Hyper ledger fabric is a private distributed ledger that provides a higher level of confidentiality, scalability, and flexibility. It does away with the concept of mining. It can also provide faster transaction throughput. It is compatible with general-purpose programming languages. It is also known as fault tolerance. Besu is an open-source distributed ledger solution that can provide a fully compatible solution. It can handle private transactions as well as integrate with public blockchains like Ethereum. They stated that Hyperledger Fabric and Hyperledger Besu are both private and business-2-business networks, whereas Ethereum is a public and business-to-customer network. Unlike Besu and Ethereum, Hyper ledger fabric lacks proper smart contract development frameworks. Furthermore, they listed some of the challenges that arise during the technology’s development, such as stakeholder agreement, where the stakeholders involved in the chain fear losing the competition in such a system. Interoperability is also viewed as a challenge that must be met. Moving forward, they discovered that malware and phishing attacks and vulnerabilities are also significant challenges in this technology. A significant challenge is also the lack of standardization, as regulatory bodies struggle to define appropriate legal boundaries for this technology. Finally, by comparing two architectures, they concluded that blockchain technology can be used to solve traceability. They also emphasized the importance of taking into account the difficulties that may arise while developing this technology.

Vishwesh Lingayat et al. (2021) [21], examined and proposed the use of blockchain technology in supply chain management in their paper. To secure the supply chain, they proposed a blockchain-based method. They discovered that blockchain is decentralized and offers greater transparency, security, and scalability. They propose a blockchain architecture called Hyperledger Fabric to implement. Because it uses a raft consensus algorithm, it is more fault-tolerant and better for building decentralized networks than Ethereum, which uses a proof of work algorithm, which is computationally more expensive. They also went over the algorithm’s operation to help you understand the subject better. Finally, they concluded that the use of blockchain technology in the supply chain provides improved transparency, tracing, and tracking of drugs in the medical supply chain.

Sachin S. Kamble et al. (2021) [18], findings are on Blockchain Technology’s Impact on Supply Chain Integration and Sustainable Supply Chain Performance: Evidence from the Automotive Industry. They investigated the requirement for supply chain integration using blockchain technology in the automotive industry. They explained the theory of dynamic capabilities. The dynamic capability of an organization is its ability to purposefully create, extend, and modify its resource base. Following that, they referred to blockchain as a technology with dynamic capabilities. To learn more about the sustainability of supply chains and the adoption of blockchain technology in the automotive industry, they conducted a survey and collected responses from 138 Indian automotive companies, concluding that Blockchain has a positive impact on organizations and their resources in supply chain management. They discovered that blockchain provides increased transparency, immutability, and ledger security.

Mohana Muniandy and Gabriel Ong Tze Ern (2019) [24], researched how to track pharmaceutical drugs in a supply chain network using blockchain technology. The blockchain-based solution improves security, transparency, and traceability. To determine the new system’s needs and requirements, the authors used a questionnaire and interviews, and the results were used to determine functional and non-functional requirements. Suppliers, manufacturers, and wholesalers are among the supply chain stakeholders who have access to the website. These participants must first login before they can add details. Any user, including doctors and pharmacists, could view the drug’s details without logging in.

Musamih et al. (2021) [26], implemented the pharmaceutical supply chain using the Ethereum blockchain for better traceability of medicines, in this work the Infura, Remix IDE, web3j, and JSON-RPC feature of the Ethereum blockchain is used. The solidity programming is used for smart contract development which gives the guarantee for data provenance security and immutability of all transactions of all stakeholders. This work presented the system architecture, algorithms, testing, and validation along with security and gas cost analysis.

Faisal et al. [15], developed a solution for drug traceability using Hyperledger in the pharmaceutical supply chain and this implementation enhanced the throughput and reduced the latency in minimum resource utilization. The rigor testing is not done and implemented for a small network.

Huang et al. [10] proposed a Drugledger for drug traceability which implements the transaction logic and authenticity and privacy of stakeholders in the supply chain. This system workflow is developed based on an expanded UTXO data structure for a package, repackage, and unpackage.

In the detailed case study (2019) [12], about the Walmart model of the blockchain-based supply chain, we found that it was difficult to develop a better traceability system for food supply in 2016 after discovering it. Walmart and International Business Machines (IBM) collaborated on this. They discovered blockchain to be a promising technology to adopt after careful consideration. IBM proposed the concept of hyper ledger fabric, and the company began with two proof-of-concept projects to test their idea. The first project involved tracing mangos, while the second involved tracing pork in China. They now have a system to trace 25 products from five different suppliers after both projects were successful. Walmart’s work demonstrates that blockchain has enormous potential for improving traceability.

Konstantinos Demestichas et al. (2020) [4], to assess the efficacy of blockchain technology for traceability in the agriculture food supply chain, I conducted a thorough review of various papers published on blockchain technology. They described the food supply chain as the most extensive and complicated, with a lack of transparency. They investigated older methods of chain traceability, such as the use of RFID tags and some IoT devices that are part of a centralized system. They discussed some of the chain’s classifications. They also listed some of the benefits of blockchain technology and promising algorithms. They also discussed how the blockchain’s hashing system operates. After researching the future potential of blockchain technology in the agricultural supply chain, it was determined that blockchain can aid in data traceability and immutability. It also aids in cost savings, risk reduction, and increased time efficiency.

After studying various research worksit is found that most of the researchers worked on Traceability, Security, Privacy, and Sustainability issue in the supply chain, and the problems were solved using blockchain technology with the help of Hyperledger Fabric and Hyperledger Besu. There is still scope to continue the research to solve the supply chain problems using different blockchain technology.

The aims of the proposed research are:

  • Propose a blockchain-based supply chain management system for drug traceability.

  • Build smart contracts for carrying out transactions.

  • Carry out traceability checks for the medicines.

These objectives are useful in overcoming such problems.

3 Proposed methodology

The proposed system’s high-level architecture diagram is shown in Fig. 1. Local blockchain network, client communication, and front end are the three stages of the architecture diagram. Stakeholders and their interactions with the system are also depicted in the diagram. The stakeholders are envisioned to access the smart contract through decentralized software devices that have a front-end layer denoted by a Decentralised Application (DAPP). The following sections provide more information about the diagram’s components.

Fig. 1
figure 1

Proposed architecture

Local Blockchain network

The local blockchain network includes ganache, truffle, and smart contracts. Ganache provides a personal in-memory Ethereum blockchain, enabling us to develop, deploy, and test your DAPP in a safe and deterministic environment. In addition, ganache provides us with 10 external accounts, each of which is preloaded with 100 fake ether and has addresses on our local Ethereum blockchain. The next sub-component is the truffle framework, which allows us to build decentralized applications on the Ethereum blockchain. It includes a set of tools for writing smart contracts in the solidity programming language. Truffle framework even allows us to test and deploy smart contracts on the local blockchain. The final and most important sub-component of the local blockchain network is smart contracts. In simple words, smart contracts are program stored on the blockchain that runs when predefined conditions are met. They typically are used to automate the execution of an agreement so that all stakeholders can be immediately certain of the outcome, without an intermediary’s involvement or time loss. When the predefined conditions have been met and verified the system will execute the actions provided. The actions can be registering a medicine, carrying out a digital transaction using the ether, etc. After the transaction is completed the blockchain will get updated and cannot be changed. The smart contracts can be written by the developer using the solidity programming language. Moreover, the various activities associated with the stakeholders are written in smart contracts in the form of functions [7, 14, 16, 17, 25, 28, 44].

Client communication

The connection between the local blockchain network and the front end is established at this stage of the architecture diagram. So that stakeholders can use the front end to trigger smart contract functions and then record the transaction on the blockchain. As a result, there will be more transparency and traceability. The first sub-component of this stage is web3.js. It is a JavaScript library that is used to develop clients or websites that can interact with the blockchain. Web3.js connects to the Ethereum Blockchain with JavaScript Object Notation Remote Procedure Call (JSON RPC). It also allows us to make requests to an individual Ethereum node with JSON RPC to read and write data to the network. Now comes the last component which helps us to connect to the Ethereum blockchain is a cryptocurrency wallet metamask. It is a browser extension for accessing Ethereum-enabled distributed applications in your browser. Metamask injects the Ethereum web3 Application Programming Interface (API) into every website’s JavaScript context so that DAPP can read from the blockchain [19, 20].

Front end

The front-end layer gives us a graphical user interface for interacting with our smart contract. It is developed with the help ofHypertext Markup Language(HTML), Cascading Style Sheets(CSS), and JavaScript. HTML is used to provide structure to the website whereas CSS and JavaScript are used to provide style and dynamic nature to the website. JavaScript is also used to write the logic for triggering smart contract functions to read and write data.

Stakeholders

Stakeholders are supply chain participants, such as the manufacturer, wholesaler, distributor, pharmacy, and customer in our system. Based on their roles in the supply chain, each stakeholder is assigned to specific smart contracts with specific functions.

4 Implementation

The Ethereum blockchain platform is being used to develop the proposed solution. Ethereum is a permissionless public blockchain, which means that anyone can access it. The truffle framework is used to compile and test the smart contract, which is written in Solidity. It provides a set of tools for creating smart contracts using the Solidity programming language. It also allows us to test and deploy smart contracts to the blockchain. Along with truffle we have used ganache which provides us with a local Ethereum blockchain for development and testing purposes. Ganache provides 10 default accounts with 100 ethers each. At last, metamask is used to make transactions with the help of decentralized applications onto the local blockchain network.

At first, the stakeholders of the supply chain must register themselves onto the decentralized application with all the necessary details and once the stakeholder is added then an event will be triggered and announced to all participants in the supply chain. Secondly, it’s the manufacturer’s responsibility to add a pre-approved medicine to the system. Once the medicine is added an event is triggered that the medicine has been added and is up for the sale. Now the interested wholesalers can initiate the purchase process and once the required funds are transferred to the manufacturer account an event will notify the purchase of medicine and transfer of ownership to all the participants and then the medicine state will get changed to PurchasedByWholesalerAndForSale. Next the third level entity i.e., a distributor along with the same level stakeholder (other wholesalers in the system) can purchase medicine from the wholesaler and transfer the funds accordingly and trigger a purchase medicine event along with the current change in the state of medicine either to PurchasedByWholesalerAndForSale or to PurchasedByDistributerAndForSale after recording the state of medicine in history to SoldByWholesaler, thus completing the purchase process by distributer. Now as mentioned above stakeholders at the same level or the pharmacy can purchase medicine from the distributer thus changing the state of medicine to either PurchasedByPharmacyAndForSale or PurchasedByPharmacyAndForSale after making a record in history along with the status to SoldByDistributer, thus transferring the ownership. At last, either the pharmacy or customer can purchase medicine from the pharmacy thus concluding the supply chain process. Customers also have an additional option to track and trace medicine with the help of medicineId or with the help of a barcode available. Finally getting a visual representation of the flow of medicine in the complete life cycle of the supply chain in Fig. 2.

Fig. 2
figure 2

Sequence diagram of the proposed system

Algorithm 1
figure a

Creating an Account for Manufacturer

In algorithm 1 the addManufacturer()function is used to add the manufacturer’s account to the decentralized application with the specific inputs mentioned abovein the blockchain.

Similarly, addWholesaler(), addDistributor(), addPharmacy(), and addCustomer() functions are used in algorithm 1 to create an account for wholesaler, distributor, pharmacy, and customer accounts respectively by changing the variable name of the functions as per the requirement.

manufacturerName: is the name of the manufacturer.

manufacturerEmailId: is the email id of the manufacturer.

manufacturerPhone: is the phone number of the manufacturer.

manufacturerPassword: is the password of the manufacturer’s account.

Algorithm 2
figure b

Manufacturer Login into the Decentralized Application.

In algorithm 2, the login() function is used for the user credentials verification before login into the application.Similarly, the login() function for wholesaler, distributor, pharmacy, and customer also follows the above-given algorithm flow just with the change in the variable names and function names.

manufacturerId: is the unique id used for decentralized applications.

manufacturerPassword: is the password used for authentication purposes.

Algorithm 3
figure c

Add Medicine.

In algorithm 3,addMedicine()function is used to add medicines to the supply chain management decentralized application. Which is further called the createMedicineHistoryRecord() function to add a medicine record and mark the beginning of the medicine life cycle into the chain.Only manufacturers can add medicines.

medicinePrefix: is the unique medicine id prefix that is generated by the javascript.

medicineName: is the name of the medicine to be added.

medicineDescription: this is a short description of the medicine.

medicinePrice: is the price associated with the medicine.

medicineExpiryDate: is the medicine expiry date.

Algorithm 4
figure d

Purchasing a Medicine

In algorithm 4,purchaseMedicine()function is used to make the purchase of medicine and record it into the decentralized application.Every stakeholder follows algorithm 4 to buy medicine in the application.

sellerId: is the unique id of the seller of the medicine.

buyerId: is the unique id of the buyer of the medicine.

medicineId: is the id associated with a particular medicine.

solDate: is the date on which the purchase is being made.

newPrice: is the updated price or the expected new price after the state change of medicine.

currentStatusCode: is the status code associated with the current state of medicine.

updatedStatusCode: is the expected change in the state of the medicine once the medicine is being bought by a particular stakeholder.

Algorithm 5
figure e

Logout from the System

In algorithm 5, the logout () function is used to change the status of the owner of the account to log out and thus exit from the decentralized application. Logout for wholesaler, distributor, pharmacy, and customer also follow algorithm 5 just with the change in the variable name.

ownerId: is the id of the stakeholder currently logged in into the system.

5 Testing and validation

To assess the smart contracts developed via Ethereum, Truffle console and the testing environment were used to test and validate different functions. The scenarios involved five accounts with different participants each representing one stakeholder of the chain and their corresponding Ethereum Addresses as presented in Table 3.

Table 3 Accounts address used to test the functions

addManufacturer(): In this function, it was tested whether a new stakeholder possessing the role of a manufacturer is able to create a new account on the system or not with the specific details. If the account is created then an event is triggered. Successful execution of the function and its corresponding logs and events are displayed in Fig. 3a and b resepectively.

Fig. 3
figure 3

addManufacturer() execution (a) and log generation (b)

Similarly addWholesaler(), addDistributer(), addPharmacy() and addCustomer() are tested if a stakeholder is able to create an account with the respective role.

Login():This function is used to login stakeholders into the decentralized system. Once the function gets executed without any error an event is triggered displaying the successful execution of the function. Here we have displayed the login activity of the manufacturer with the successful execution of the function and its corresponding logs and events in Figs. 4a and b respectively.

Fig. 4
figure 4

Login() execution (a) and log generation (b)

Similarly, the function will work for all the other stakeholders.

addMedicine(): This function is used by the manufacturer to add medicine to the decentralized application and to initiate the supply chain flow by marking the medicine for sale. If the medicine gets added without encountering any error,then an event is declared to all the participants of the chain the successful addition of the medicine else the state of the contract is reverted, and an error is thrown. Successful execution of the function and its corresponding logs and events are displayed in Figs. 5a and b respectively.

Fig. 5
figure 5

addMedicine() execution (a) and log generation (b)

purchaseMedicine(): This function is used by the following stakeholders for the purchase of medicine either from the same level stakeholder or from the one just above them in the supply chain network. When this function is called some specific checks are being made and the ownership of medicine is transferred to the new owner after the successful transfer of the fund. At last, a record is being recorded in the history with the createMedicineHistoryRecord function and an event is declared. If by chance any security check fails then the contract state is reverted and an error is shown. Figures 6 and 7 shows the manufacture and wholesaler balance before purchase and Fig. 8 shows the manufacture and wholesaler balance after purchase. The Successful execution of the function and its corresponding logs and events are displayed in Fig. 7a and b respectively.

Fig. 6
figure 6

Manufacturer (accounts [38]) and wholesaler (accounts [29]) balance before purchase

Fig. 7
figure 7

purchaseMedicine() execution (a) and log generation (b)

Fig. 8
figure 8

Manufacturer (accounts [38]) and wholesaler (accounts [29]) balance after purchase

Fig. 9
figure 9

Logout execution (a) and log generation (b)

Fig. 10
figure 10

Ganache accounts

Fig. 11
figure 11

Contract deployment

Fig. 12
figure 12

Account creation

Fig. 13
figure 13

Stake holder login

Fig. 14
figure 14

Manufacturer add medicine

Fig. 15
figure 15

Buy medicine window

Fig. 16
figure 16

Trace medicine window

Fig. 17
figure 17

Full trace of medicine

logout: This function is used to log out users from the decentralized application and change status to logged out. Once the function gets executed without any error an event is triggered displaying the successful execution of the function. Successful execution of the function and its corresponding logs and events are displayed in Figs. 9a and b respectively.

6 Results and discussions

Ganache provides some blockchain account that contains fake ether which can be used as gas to deploy the smart contract. In Fig. 10, the account provided by ganache is visible with the amount of fake ether in them, it also shows the number of transactions done by that account address.

Figure 11 shows the deployment of the smart contracts on the console system console

Table 4 shows the amount of gas used to deploy a smart contract on the blockchain network and the contract address generated. The account address for all the smart contracts is the same because the system has used only one account to deploy all the smart contracts.

Table 4 Smart contract deployment

Average Gas Used for Contract Deployment = Sum of Gas Used for Contract Deployment/Number of Contracts Deployed

$$ =9172445/7=1310349.29 $$

Figure 12 shows the account creation form after filling in all the information on clicking submit a connection request is generated through metamask on confirming which account is added to the chain.

Table 5 shows the amount of gas used to create an account for a particular stakeholder with a specific account address provided by the ganache. And the Gas limit is the maximum amount of gas allowed to be used for a transaction.

$$ {\displaystyle \begin{array}{c}\mathrm{Average}\ \mathrm{gas}\ \mathrm{used}\ \mathrm{to}\ \mathrm{create}\ \mathrm{manufacturer}\ \mathrm{account}=\mathrm{Sum}\ \mathrm{of}\ \mathrm{gas}\ \mathrm{used}/\mathrm{Total}\ \mathrm{Manufacturer}\ \mathrm{added}\\ {}=594060/3=198020\\ {}\begin{array}{c}\mathrm{Average}\ \mathrm{gas}\ \mathrm{used}\ \mathrm{to}\ \mathrm{create}\ \mathrm{wholesaler}\ \mathrm{account}=\mathrm{Sum}\ \mathrm{of}\ \mathrm{gas}\ \mathrm{used}/\mathrm{Total}\ \mathrm{Wholesaler}\ \mathrm{added}\\ {}=594174/3=198058\\ {}\begin{array}{c}\mathrm{Average}\ \mathrm{gas}\ \mathrm{used}\ \mathrm{to}\ \mathrm{create}\ \mathrm{Distributer}\ \mathrm{account}=\mathrm{Sum}\ \mathrm{of}\ \mathrm{gas}\ \mathrm{used}/\mathrm{Total}\ \mathrm{Distributer}\ \mathrm{added}\\ {}\begin{array}{c}=594036/3=198012\\ {}\begin{array}{c}\mathrm{Average}\ \mathrm{gas}\ \mathrm{used}\ \mathrm{to}\ \mathrm{create}\ \mathrm{Pharmacy}\ \mathrm{account}=\mathrm{Sum}\ \mathrm{of}\ \mathrm{gas}\ \mathrm{used}/\mathrm{Total}\ \mathrm{Pharmacy}\ \mathrm{added}\\ {}=594150/3=198050\\ {}\begin{array}{c}\mathrm{Average}\ \mathrm{gas}\ \mathrm{used}\ \mathrm{to}\ \mathrm{create}\ \mathrm{Patient}\ \mathrm{account}=\mathrm{Sum}\ \mathrm{of}\ \mathrm{gas}\ \mathrm{used}/\mathrm{Total}\ \mathrm{Patient}\ \mathrm{added}\\ {}=593988/3=197996\\ {}\begin{array}{c}\mathrm{Average}\ \mathrm{gas}\ \mathrm{used}\ \mathrm{to}\ \mathrm{create}\ \mathrm{all}\ \mathrm{the}\ \mathrm{account}\mathrm{s}=\left(198020+198058+198012+198050+197996\right)/5\\ {}=990136/5=\kern0.5em 198027.2\end{array}\end{array}\end{array}\end{array}\end{array}\end{array}\end{array}} $$
Table 5 Gas used to create stakeholder account

Figure 13 shows the login window. Where a stakeholder fill in the id and password and on clicking submit he has to confirm the request generated through the metamask to log into the system.

Table 6 shows the amount of gas used to log in to the system with a particular login id of a stakeholder.

$$ {\displaystyle \begin{array}{c}\begin{array}{c}\begin{array}{c}\begin{array}{c}\mathrm{Average}\ \mathrm{gas}\ \mathrm{used}\ \mathrm{to}\ \mathrm{login}\ \mathrm{manufacturer}\ \mathrm{account}=\mathrm{Sum}\ \mathrm{of}\ \mathrm{gas}\ \mathrm{used}/\mathrm{Total}\ \mathrm{Manufacturer}\ \mathrm{added}\\ {}=14804/3=49348\\ {}\mathrm{Average}\ \mathrm{gas}\ \mathrm{used}\ \mathrm{to}\ \mathrm{login}\ \mathrm{Wholesaler}\ \mathrm{account}=\mathrm{Sum}\ \mathrm{of}\ \mathrm{gas}\ \mathrm{used}/\mathrm{Total}\ \mathrm{Wholesaler}\ \mathrm{added}\end{array}\\ {}=143433/3=47811\\ {}\mathrm{Average}\ \mathrm{gas}\ \mathrm{used}\ \mathrm{to}\ \mathrm{login}\ \mathrm{Distributer}\ \mathrm{account}=\mathrm{Sum}\ \mathrm{of}\ \mathrm{gas}\ \mathrm{used}/\mathrm{Total}\ \mathrm{Distributer}\ \mathrm{added}\end{array}\\ {}=143367/3=47789\\ {}\mathrm{Average}\ \mathrm{gas}\ \mathrm{used}\ \mathrm{to}\ \mathrm{login}\ \mathrm{Pharmacy}\ \mathrm{account}=\mathrm{Sum}\ \mathrm{of}\ \mathrm{gas}\ \mathrm{used}/\mathrm{Total}\ \mathrm{Pharmacy}\ \mathrm{added}\end{array}\\ {}=143433/3=47811\\ {}\begin{array}{c}\mathrm{Average}\ \mathrm{gas}\ \mathrm{used}\ \mathrm{to}\ \mathrm{login}\ \mathrm{Patient}\ \mathrm{account}=\mathrm{Sum}\ \mathrm{of}\ \mathrm{gas}\ \mathrm{used}/\mathrm{Total}\ \mathrm{Patient}\ \mathrm{added}\\ {}=143502/3=47834\\ {}\begin{array}{c}\mathrm{Average}\ \mathrm{gas}\ \mathrm{used}\ \mathrm{to}\ \mathrm{login}\ \mathrm{to}\ \mathrm{all}\ \mathrm{the}\ \mathrm{account}\mathrm{s}=\left(49348+47811+47789+47811+47834\right)/5\\ {}=240593/5=48118.6\end{array}\end{array}\end{array}} $$
Table 6 Gas used to login in system

Figure 14 shows that the manufacturer added the medicine details and the gas amount is spent through metamask after a click on the confirmation button and then medicine is added to the blockchain.

Table 7 shows the amount of gas used to add a medicine to the system. This functionality is allowed only to the manufacturer.

$$ {\displaystyle \begin{array}{c}\mathrm{Average}\ \mathrm{gas}\ \mathrm{used}\ \mathrm{by}\ \mathrm{manufacturer}\ \mathrm{to}\ \mathrm{add}\ \mathrm{medicine}=\mathrm{Sum}\ \mathrm{of}\ \mathrm{gas}\ \mathrm{used}/\mathrm{Total}\ \mathrm{Medicines}\ \mathrm{added}\\ {}=2302044/6=383674\end{array}} $$
Table 7 Gas used to add the medicine

Figure 15 shows the amount to be transferred for a transaction made by a stakeholder to buy medicine on confirming the stated amount is transferred to the stakeholder from which the medicine is purchased.

Table 8 shows the amount of gas used to buy the medicine. This functionality is available for all stakeholders other than the manufacturer.

$$ {\displaystyle \begin{array}{c}\begin{array}{c}\begin{array}{c}\begin{array}{c}\begin{array}{c}\mathrm{Average}\ \mathrm{gas}\ \mathrm{used}\ \mathrm{by}\ \mathrm{wholesaler}\ \mathrm{to}\ \mathrm{buy}\ \mathrm{medicine}=\mathrm{Sum}\ \mathrm{of}\ \mathrm{gas}\ \mathrm{used}/\mathrm{Total}\ \mathrm{medicines}\ \mathrm{purchased}\\ {}=1795224/6=299204\end{array}\\ {}\mathrm{Average}\ \mathrm{gas}\ \mathrm{used}\ \mathrm{by}\ \mathrm{Distributer}\ \mathrm{to}\ \mathrm{buy}\ \mathrm{medicine}=\mathrm{Sum}\ \mathrm{of}\ \mathrm{gas}\ \mathrm{used}/\mathrm{Total}\ \mathrm{medicines}\ \mathrm{purchased}\\ {}=1705506/6=284251\end{array}\\ {}\mathrm{Average}\ \mathrm{gas}\ \mathrm{used}\ \mathrm{by}\ \mathrm{Pharmacy}\ \mathrm{to}\ \mathrm{buy}\ \mathrm{medicine}=\mathrm{Sum}\ \mathrm{of}\ \mathrm{gas}\ \mathrm{used}/\mathrm{Total}\ \mathrm{medicines}\ \mathrm{purchased}\\ {}=1706070/6=284345\end{array}\\ {}\mathrm{Average}\ \mathrm{gas}\ \mathrm{used}\ \mathrm{by}\ \mathrm{Patient}\ \mathrm{to}\ \mathrm{buy}\ \mathrm{medicine}=\mathrm{Sum}\ \mathrm{of}\ \mathrm{gas}\ \mathrm{used}/\mathrm{Total}\ \mathrm{medicines}\ \mathrm{purchased}\\ {}=1681434/6=280239\end{array}\\ {}\mathrm{Average}\ \mathrm{gas}\ \mathrm{used}\ \mathrm{to}\ \mathrm{buy}\ \mathrm{all}\ \mathrm{the}\ \mathrm{medicines}\ \mathrm{by}\ \mathrm{all}\ \mathrm{stakeholders}=\left(299204+284251+284345+280239\right)/5\\ {}=1148039/5=229607.5\end{array}} $$
Table 8 Gas Used to buy the medicine

In Fig. 16 the option for entering a medicine id or uploading the QR code of medicine to trace its ownership and price history. In Fig. 17 the full trace of medicine is shown. History shows that the price of medicine is increased whenever its ownership is changed as there is a definite margin of profit that is to be earned by the stakeholder and also, they cannot sell it for a higher amount to earn more profit.

Table 9 shows the amount of gas used to log out from the system.

$$ {\displaystyle \begin{array}{c}\begin{array}{c}\begin{array}{c}\begin{array}{c}\mathrm{Average}\ \mathrm{gas}\ \mathrm{used}\ \mathrm{to}\ \mathrm{logout}\ \mathrm{manufacturer}=\mathrm{Sum}\ \mathrm{of}\ \mathrm{gas}\ \mathrm{used}/\mathrm{Total}\ \mathrm{manufacturer}\ \mathrm{accounts}\\ {}=42798/3=14266\\ {}\mathrm{Average}\ \mathrm{gas}\ \mathrm{used}\ \mathrm{to}\ \mathrm{logout}\ \mathrm{Wholesaler}=\mathrm{Sum}\ \mathrm{of}\ \mathrm{gas}\ \mathrm{used}/\mathrm{Total}\ \mathrm{Wholesaler}\ \mathrm{accounts}\end{array}\\ {}=42831/3=14277\\ {}\mathrm{Average}\ \mathrm{gas}\ \mathrm{used}\ \mathrm{to}\ \mathrm{logout}\ \mathrm{Distributer}=\mathrm{Sum}\ \mathrm{of}\ \mathrm{gas}\ \mathrm{used}/\mathrm{Total}\ \mathrm{Distributer}\ \mathrm{accounts}\end{array}\\ {}=42798/3=14266\\ {}\mathrm{Average}\ \mathrm{gas}\ \mathrm{used}\ \mathrm{to}\ \mathrm{logout}\ \mathrm{Pharmacy}=\mathrm{Sum}\ \mathrm{of}\ \mathrm{gas}\ \mathrm{used}/\mathrm{Total}\ \mathrm{Pharmacy}\ \mathrm{accounts}\end{array}\\ {}=42831/3=14277\\ {}\begin{array}{c}\mathrm{Average}\ \mathrm{gas}\ \mathrm{used}\ \mathrm{to}\ \mathrm{logout}\ \mathrm{Patient}=\mathrm{Sum}\ \mathrm{of}\ \mathrm{gas}\ \mathrm{used}/\mathrm{Total}\ \mathrm{Patient}\ \mathrm{accounts}\\ {}=42867/3=14289\\ {}\begin{array}{c}\mathrm{Average}\ \mathrm{gas}\ \mathrm{used}\ \mathrm{to}\ \mathrm{logout}\ \mathrm{of}\ \mathrm{all}\ \mathrm{the}\ \mathrm{accounts}=\left(14266+14277+14266+14277+14289\right)/5\\ {}=71378/5=14275\end{array}\end{array}\end{array}} $$
Table 9 Logout

Table 10 represented the comparison of the proposed approach with existing approaches Musamih et al.[26]on the basis of various paraments, the proposed approach is better than an existing solution because the proposed solution’s gas cost is less than the existing approach and off-chain data storage is not used in the proposed approach but is used in the existing approach. And gas cost analysis is not done by the other three existing approaches Faisal et al. [15], Huang et al. [10] and Pandey & Litoriya [33]. However, the gas cost is dependent on the number of variables and computing cost so it can be varied from function to function and hardware used. The gas cost can be converted to any currency as per the conversion rate as of date. The comparative analysis clearly indicates the superiority of the proposed method over the existing one in terms of various critical parameters, which directly or indirectly play a crucial role in implementing blockchain commercially.

Table 10 Comparative analysis of different features of the proposed blockchain-based solution with the existing approaches

The proposed blockchain implementation’s running time is a function of the number of blocks and average synchronization delay. The proposed method involves a random network model that adheres to a standard protocol. Massive block discarding, a blockchain efficiency issue, is rare in “slow” block-producing blockchains. The time needed to produce a new block allows workers to synchronize their local blockchains. Slow blockchain systems prevent workers from wasting resources and time on blocks that will be discarded soon. In Bitcoin, a block is produced in 10 minutes and updated in 12.6 seconds [3]. Bitcoin forked 1.78% in 2013. As blockchain finds new uses, faster block production is needed [2]. Understanding how speed-ups in block production can negatively impact blockchains in terms of blocks discarded due to race conditions is important for designing new fast and efficient blockchains.

7 Conclusions

Every country must have a secure and transparent healthcare supply chain, which can be done using blockchain technology, which includes smart contracts, ganache, Metamask, and the truffle framework. The application’s frontend is built with HTML, CSS, and JavaScript, and it connects to blockchain technology via a Web 3.0 Application Programming Interface (API). And smart contracts are written in the Ethereum-based Solidity programming language and deployed on the blockchain network using ganache. The algorithm for stakeholders and medicine smart contracts has been implemented, and users can interact with the interface using a browser by creating an account first and using the generated credentials by connecting it to the blockchain network via Metamask. The manufacturer can add medicines to the system and sell them to the other stakeholders. All the stakeholders can buy and sell medicine, except the customer, who can only buy medicine. The results are worked out by making three accounts for each stakeholder on a computer with 16 gigabytes of RAM and an Intel(R) Core(TM) i5-7200U–CPU@2.50GHz, 2.70GHz processor. A certain amount of gas is used to perform a network transaction, which does not exceed the transaction’s gas limit. If the amount of gas required (used) for a particular transaction exceeds the gas limit, the transaction is unable to complete and fails. There is a fixed and equal profit margin set for each stakeholder, which causes a slight increase in the price of the medicine whenever it changes ownership and cannot exceed the maximum retail price when it reaches the patient. This ensures that the stakeholders make an equal profit on the sale of the medicines and that the patient is not duped by the prices as he is aware of the changes in ownership and the prices of the medicine. The average gas cost to deploy a smart contract is calculated as 1,310,349.29. For creating a manufacturer account, the gas cost is 198,020. For the wholesaler account, it is 198,058. Whereas the distributer costs 198,012 and the pharmacy costs a gas amount of 198,050, the cost of patient account creation is 197,996. The average gas cost for individual stakeholders to login into the system is calculated. For manufacturers, it is 49,348; for wholesalers, it is 47,811; for distributors, it is 47,789; for pharmacies, it is 47,811; and for patients, it is 47,834. The average gas cost required to add medicine by a manufacturer is 383,674. To buy medicine, the average gas cost for every stakeholder is calculated. For the wholesaler, it is 299,204, the distributor requires 284,251, the pharmacy costs 284,345, and for the patient, it is 280,239. To log out of the system, the average gas cost for the manufacturer is 14,266; for wholesalers, it is 14,277; for distributors, it is 14,266; the pharmacy needs 14,277; and for patients, it costs 14,289. The overall average gas cost to create all the accounts is calculated as 198,027.2. Overall, the average log gas cost is 48,118.6 to purchase medicine, the overall average amount of gas cost is 229,607.5 and to log out, the overall average gas cost is 14,275. The kind of economic analysis for implementing the state of art technology in Pharma supply chain is unique and opens the avenue to make medicine business, more secure, traceable, and genuine by analyzing the deployment cost as per their scope.

8 Future scope

People should be taught about and encouraged to use blockchain technology in the healthcare supply chain for every country to implement it. There should be a public discussion about technology to overcome challenges such as the fear of losing competency for market stakeholders. Each government should make a secure cryptographic digital payment system legal. For improved results, the technology can also be integrated with IoT-based devices.