Generating a Blockchain Smart Contract Application Framework

,


Introduction
Blockchain is one of the trending technologies of today, but it was found in 1992. Although it was found at that time, its name began to be heard more frequently in 2009 with the use of technology as the basis of Bitcoin. Initially, the advantages of Blockchain were overshadowed by the popularity of Bitcoin, and what these technologies promised was not clearly understood. Bitcoin managed to place the concept of crypto money in the literature, and later many similar cryptocurrencies began to take its place in the market. The advantages of Blockchain, the technology that is the basis of cryptocurrencies, are much more than that. Blockchain is not only for financial transactions; it is a technology that can be programmed to record anything of value and importance, and where transactions are stored in a digital distributed ledger that is intact. This value can be anything that can be expressed in code. Values such as supply chain management, food tracking, land registration can be easily managed this way. It is envisaged that concepts such as driver license, marriage certificate, birth certificate and smart property exchange can be managed easily and securely with Blockchain technology. Having such a wide range of uses makes Blockchain technology attractive. With its increasing popularity, Blockchain has started to be described as "New Internet". Just as the internet provides a structure for communication, it is argued that a similar structure for information sharing will be provided by Blockchain. The ground for this ambitious argument stems from the revolutionary attributes of Blockchain technology. Blockchain distributed ledger structure comes first among these revolutionary qualities. The distributed ledger is the structure in which all transactions performed on the system are recorded. A copy of this ledger is shared with all parties in the system. All transactions on the network are recorded and stored in the nodes where all participants are located. With the distributed ledger structure, the security of the data is ensured within the system parties. Thus, the need for a third-party central authority such as bank and notary is eliminated. Even though it is a relatively new technology, due to these impressive advantages, the number of studies on it has increased significantly. Many large-scale companies are investing in Blockchain technology and conducting projects using this technology.
Blockchain technology allows clients and providers to operate securely with each other directly, without the need for approval by any third party. All transactions are stored in a distributed database using cryptography so that this exchange between client and provider can be done securely. To be able to make changes to the data in the system, that change has to be recorded in the majority of the parties in the system. To succeed in any chain of cyberattacks, it is necessary to verify over at least 50% of the computers, which makes the probability almost impossible.
Five principles are at the heart of Blockchain technology [1]: • Distributed Database Structure: Each member of the network has access to data with the entire history. There are no single control points or central authority.
• Peer to Peer Communication: The communication takes place between the nodes directly, instead of being controlled from a central control point. Each party in the system stores the information and transmits it to other participants.
• Pseudonymity: Pseudonymity definition comes with Blockchain. Each transaction can be seen by the participants who have access to the system within the framework of the authority granted. In the Blockchain network, each user has a unique address that identifies it in the system. With this idea, users can choose to remain anonymous or prove their identity to others.
• Irreversibility of Records: In the system, each record is stored by associating it with the previous data. In case any record registered in the system is changed or a new record is added to the system, this link will be broken, so manipulation is detected. Thus, it is not possible to manipulate data on the system, which makes the system cyber-attack resistant. Various computational algorithms are used to create interconnected chains on the system. By using this calculation algorithm, the system is created in chronological order and avoids manipulation. To succeed in any chain of cyberattacks, it is necessary to verify over at least 50% of the computers, which makes the probability almost impossible.
• Computational Logic: With the automated structure of Blockchain, all operations performed are carried out based on calculation algorithm logic and programming. Therefore, with this established automated structure, users perform the transactions between them within the framework of pre-determined rules.
After evaluating all these advantages, many companies start to develop new applications on Blockchain. When we combine the reliability of Blockchain technology against cyber threats and the demands of clients and providers to make a secure exchange, Blockchain application areas are emerging. Applications are developed and still being developed in many different areas using Blockchain technology. Health, Digital Right Management, the Internet of Things (IoT) are the most popular of these areas. Up to date a lot of application has already been developed and it is predicted that the number of applications will increase in the coming period.
Gartner, which is one of the most important companies performing the current condition and market analysis of new generation technologies, has not been insensitive to Blockchain technology and has evaluated this technology within the scope of emerging technologies research. They published a report called "Emerging Technologies". In this report, "Hypecycle" curve, which shows the roadmap of emerging technologies, it could be seen that Blockchain looks to exceeded the "Peak of Inflated Expectations" and moving to "Trough of Disillusionment" phase ( Fig. 1). It is also emphasized that it will take five to ten years for the technology to reach its efficiency. When we examine the hype curve, the fact that Blockchain technology is in a downward trend shows that it cannot exceed the expected threshold in less than 5 years. With the works to be carried out in the next 5-10 years, the capabilities of the technology will be fully revealed, and the applications developed using this technology will eliminate the shortcomings in the current situation and ensure that the technology will reach maturity. Harvard has not been indifferent to the popularity and advantages of Blockchain technology and has conducted research. In the Harvard Business Review, they have defined Blockchain technology as a facilitator that enables contracts to be embedded in digital code. This digital contract environment enables data to be stored transparently with a shared database structure that protects data from tampering. This digitalization makes every deal, process, task and payment to have a digital record and signature that enables identification, authentication, storage and sharing. Hence, the mandatory need for a trusted third party will no longer be valid. Blockchain technology enables people, organizations and machines to interact individually with each other quickly, easily and securely without requiring central trust. It can be said that the enormous potential of Blockchain comes from here [1]. Turkey is one of the emerging countries are investing in new generation technology. Especially, ensuring digitalization across the country is one of the main short and medium-term goals set by the government. In line with this goal, technology companies across the country are encouraged to invest in emerging technologies and contribute to digitalization to accelerate the country's development. HAVELSAN adopts this goal of the government regarding digitalization and operates as a large-scale software defense company that develops and applies emerging technologies in its field of activity. After evaluating that Blockchain technology is a new generation technology with high potential that cannot be ignored and evaluating that we can develop projects and products suitable for our fields of activity, we determined to create HAVELSAN Smart Contract framework. With this framework to be developed, we aimed to develop Blockchain-based applications suitable for the company's fields of activity. The creation of HAVELSAN Blockchain Smart Contract Framework; which infrastructures are used during the development phase, the problems encountered during development and the structure of the most suitable applications to be developed with the framework to be created will be explained in this article.

Infrastructure Selection
Concepts such as Smart Contract, Smart Property are the terms where Blockchain technology is used together, which indicates the value ownership in the digital environment. Smart contracts define the rules and flow that enable the cases that we attach value to operate automatically as determined without the need for an external trigger mechanism. The Smart Contract structure is a key concept to achieve all the advantages offered by Blockchain technology. Smart Contracts not only define the rules and penalties around a contract like a traditional contract does, but also automatically enforce those obligations. The flow is carried out completely automatically and no manual intervention is possible. This means that there is no need for any authority to manage the flow, that is, to run the flow with the consensus between the parties. With this extraordinary structure, Blockchain technology stands out and becomes the reason for preference. When we look at the idea of smart contracts, we see that it was proposed by Nick Szabo in 1997 [3]. Nick Szabo argues that through smart contracts, a structure in which digital contracts can be triggered can be established with the structure to be set up digitally. Although the idea of the Smart Contract was put forward by Nick Szabo, we see that the idea of smart property was proposed by Mike Hearn in 2012 [4]. Mike Hearn proposed the idea of smart property, thereby arguing that the property status and the transfer process can be monitored. Blockchain applications are developed using smart contracts infrastructure and it is not possible to develop Blockchain applications in a different structure. With the smart contract structure to be designed, it is possible to develop products in a wide range of desired areas. Therefore, it is wrong to think of the smart contract structure as a single application. The smart contract structure is a framework in which applications can be developed on. Based on this point; after evaluating that HAVELSAN has a wide area of activity, we decided to develop a smart contract framework that enables the development of applications in different areas instead of developing a single Blockchain-based application. In order to create such a frame structure, it is important to construct the structure carefully from the beginning. It is the first option to construct the services and infrastructure to be offered from scratch. However, there are many infrastructure providers currently offering smart contract infrastructure and allowing us to create our framework. These organizations have many experiences in providing such services. We can obtain similar experience and knowledge by working, but it does not seem logical when considering the need for rapid action in the age of information sharing. Instead of rediscovering the same things again, taking such services from the service providers who have experienced and present mature solutions and establishing our framework on this will contribute to creating a more effective and strong structure. The starting point of the study; when we consider the purpose of creating a strong framework in which HAVELSAN can develop applications with different qualities suitable for its fields of activity, it seems reasonable to receive service from such a service infrastructure provider. For this reason, as the first step of our road map, basic services will be obtained using open source infrastructure providers, and we will create our Smart Contract Infrastructure. When we examine who are the open-source infrastructure providers, Ethereum, Hyperledger, Corda, which are the most powerful organizations in this field, appear.
Ethereum is one of the most popular among smart contract providers. Ethereum was announced by Vitalik Butterin in 2015 and is a smart contract infrastructure platform where many cryptocurrencies currently operating in the market are developed. Apart from cryptocurrencies, it offers its users a structure to create a smart contract protocol and provides the opportunity to develop different applications using this infrastructure [5]. Ethereum allows its users to develop their smart contract-based applications using Solidity language.
R3 Corda is another smart contract infrastructure service provider. Similar to Ethereum, Corda offers smart contract infrastructure for the development of Blockchain applications. Corda is a Blockchain platform developed by R3 and its first version was released in 2016. R3 has entered the Blockchain world with a different product by working with more than two hundred members and partners in the development process, revealing the permissioned Blockchain architecture for financial services, insurance and the business world. With its smart contract infrastructure, R3 Corda allows its users to develop their smart contract-based applications using Java and Kotlin languages. With the infrastructure provided by R3 Corda, users can establish their permissioned type Blockchain networks [6].
Thirdly, Hyperledger is another alternative considered. Hyperledger was founded by the Linux Foundation in 2016, adopting the principle of developing an open-source infrastructure and setting standards that could not be achieved for Blockchainbased application development. Within this organization, it is an organization with more than 50 members in total, with many companies from the financial sector, as well as important companies in the world of technology such as IBM and Fujitsu. With the basic principle of establishing a standard for distributed databases, they aim to develop Blockchain technology by creating an open standard platform across industries and institutions for distributed databases. It is advocated that with this platform, the way of developing applications in different fields can be opened, thus, a new setup will emerge that will include different actors on a global basis. Unlike its competitors, which currently offer Blockchain-based smart contract infrastructure, the Hyperledger Project has targeted areas of application outside of cryptocurrencies since its first appearance. It is seen that Hyperledger produces a wide range of solutions for different needs for incubation at all development stages for enterprise-class Blockchain [7] (Figure 2). Fabric is one of the most popular products offered by Hyperledger. It has been the reason for the preference of users especially with its modular structure and flexible architecture. Fabric offers its users a smart contract infrastructure suitable for various usage scenarios. It also offers the flexibility to apply the consensus model suitable for the applications to be developed. Hyperledger Fabric is the first Blockchain network created in a specific standard using programming languages, without any cryptocurrency dependency. Besides, having a structure that supports digital identity enables the development of applications in a wide range of products. Currently, the Proof of Work (PoW) consensus algorithm used in many Blockchain applications, such as Bitcoin and other cryptocurrencies, does not have to be used, so it offers important solutions to overcome problems such as resource consumption and performance [8]. When the infrastructure that can be used in building our structure in Blockchain technology is examined, these three organizations stand out seriously. The truth is different, although it is thought that all three alternatives are provided with a similar quality of service, that is, it allows us to define smart contract rule protocol. There are differences such as the type of service provided, usage area. When we evaluate that we will establish our smart contract infrastructure; it is of great importance for us to determine the need criteria correctly and to create the structure healthily.
As the first criterion, the usage area of the structure to be created must be determined correctly. Will the applications be developed in the financial field or will the financial applications be excluded from our field? The answer to this question is important for determining the smart contract service provider. Corda can be considered as the optimum solution if it is desired to create a Blockchain framework for financial applications. However, for our case, choosing Corda does not make sense because we do not intend to develop any financial applications.
After determining the application area, how the nodes are included in the system to be installed and their authorization is another criterion. As is known, basically 2 types of Blockchain networks can be established; public and permissioned. Public Blockchain network is the network where the nodes in the system can freely join the system as a participant or authenticator without going through any control mechanism. Bitcoin and other cryptocurrencies generally aim to set up such a network and ensure that the participants are freely included in the system. On the other hand, there is a need for the parties to join the system to participate in the network as a result of having a certain check under certain criteria. Private Blockchain networks are being established for those in this situation. In order to join the system in the private Blockchain network and be able to read the data on the network, certain authorization must be made [10]. At this point, the solution offered by service providers differ. When we compare Ethereum and Hyperledger solutions, it is seen that there is a difference in terms of public and private networking opportunities. Ethereum provides its users with an infrastructure to establish a public Blockchain, while Hyperledger allows users to set up a private Blockchain according to their needs. In addition, we can say that Hyperledger offers its users a wider choice in terms of setting up the network.
When our needs are evaluated; since we aim to develop applications with specific needs for specific customers, private Blockchain and offering more flexible options seem more appropriate to meet our needs. Therefore, it appears that Hyperledger fully meets these criteria. As a result, the Hyperledger was chosen as the infrastructure to be used when developing our Blockchain application framework, and the study was carried out using this infrastructure. The screenshot of the login page of the developed Blockchain Smart Contract Application Framework is given in Figure 3.

Problems
After choosing the Hyperledger infrastructure for the framework application to be developed, it was necessary to choose the most suitable tools. In the next step after deciding to use Hyperledger, various Hyperledger solution alternatives have been evaluated to find the appropriate solution for which tool to install the network, the distribution of the network and the installation of the smart contract structure. Different solutions such as Hyperledger Fabric, Sawtooth, Burrow and Indy are available in the marketplace [11]. Hyperledger Fabric is the most preferred and most popular among these options. Hyperledger Fabric offers an infrastructure that does not have a cryptocurrency dependency and enables the development of enterprise-level Blockchain applications. Due to the factors such as enabling the use of different consensus methods, enabling the operations to be shown in a grouped manner safely thanks to its channel structure, its modular structure and ease of use, Fabric overrides other options. After considering all these advantages, it was decided to use it within the smart contract framework project. A sub-module is also needed for the distribution and display of the network formed with fabric. At this point, the use of Cello and Composer, among the existing solutions, are the highlights of the options. Hyperledger Cello offers an advanced interface for networking and deployment to meet this need. Using Cello, it is possible to securely distribute and display the Blockchain network. It allows us to create a private and highly secure Blockchain network that allows us to instantly see changes in the network regardless of the size of the network. For all these reasons, it was decided to use Hyperledger Fabric & Cello. After this decision, some difficulties had to be overcome to get a useful framework.
Lack of resources is the first problem encountered, since Hyperledger is a new organization established in 2016. The number of projects developed and used by using Hyperledger infrastructure is limited, and there are not enough projects completed to transfer the experiences gained to new projects. The development of the Hyperledger project is still ongoing. The organization has released many versions. As a result of the experiences and feedbacks, the release of advanced versions continues periodically. User manuals for Hyperledger services are available to everyone over the internet. However, since the history of the services provided is not very old, the number of studies carried out using Hyperledger in the literature is very limited. When a problem is encountered during the development phase, research is done on the internet, and the problem encountered is solved quickly by using resources that encounter similar problems and produce solutions. Since there was a limited number of Hyperledger applications in the literature, it causes difficulties in quickly overcoming the problems encountered during the application development phase. During the development process, it was not possible to solve some problems with the existing documents, it was possible to find solutions to the problems by examining the source code and performing various trials. This process took more time than expected and caused high effort.
The second important problem encountered concerns the display of blocks to users. We can say that we had difficulty to show detailed information about the newly added block. Data on the network created by Hyperledger Fabric is kept in a closed box structure with high security. In this structure, it is possible to access the data on the blocks only with the commands provided by Fabric. Due to this restriction, limitations are encountered in accessing block data through the developed application layer. This led to insufficient flexibility during development. If we cannot access detailed information about the blocks, it will cause us to have problems at the point of the display to the end-users. If the user cannot have enough information about the blocks, he/she will have problems controlling the system and it will be difficult to adopt the system. If the data held on the blocks remain hidden, this will create a mystery. As a result of this mystery, users may tend to avoid the system due to uncertainty. For users to be familiar with the system, they must have sufficient access to the blocks and the information they contain. Otherwise, we would have missed the transparency advantage offered by Blockchain, which causes the system's success to be questioned. In order to avoid this uncertainty, we had to research how detailed information about the blocks could be shown. We wrote different functions from the display layer of the data for detailed access to the data on the layer on which it was kept. With the prepared methods, queries were prepared, in which we can access the details of the block-related address and the data kept, such as Hash Number, Previous Hash and Transaction ID.
The third problem encountered is the problems experienced at the point of integration. Thanks to the high security smart contract infrastructure offered by Hyperledger Fabric, there is no shortage in developing a closed box smart contract infrastructure. Fabric and Cello tools used for network distribution and network representation enable us to obtain a closed box system. It helps to protect the system at a high level and to make transactions safer and without intermediaries. However, when it is desired to get an application-level infrastructure with all these advantages, it is observed that this planned structure is limited in terms of providing integration points. We need a different solution to overcome this problem. At this point, it has been observed that Hyperledger Composer offers a more flexible solution for the establishment of integration points and communication in high integration applications. Hyperledger Fabric offers a flexible solution for the lower-level design and architectural installation. Hyperledger composer offers an additional layer over the structure offered by Hyperledger Fabric. With this created layer, integration and application development are carried out by Composer.
Hyperledger Composer offers its users an interface that facilitates and speeds up the development phase. The components offered through this interface provide a simpler understanding of the development. Hyperledger Composer, written in JavaScript, paves the way for integration with external systems thanks to the possibility of creating the Rest API. Blockchain applications developed are easily integrated with external systems using these Rest APIs. Since it has emerged as a new solution, the Hyperledger Composer solution was introduced while we were in development, so it was not possible to plan it at the beginning of development. As a result of all these experiences, it can be said that it is more appropriate to use Hyperledger Composer in high integration applications. The problem we face is solved by transferring operations in the work to Hyperledger Composer using smart contracts based on Hyperledger Fabric, especially at the point of integration. As a result of all these experiences, it has been seen that it is appropriate to use Hyperledger Composer tool for applications where intervention is required and applications that do not require independence from external systems. Composer selection will be reasonable especially in systems that require integration due to the possibility of communicating with Rest APIs. Although we did not use Composer during the system development period, we managed to solve the problem by moving the existing structure to Composer after this problem we encountered during the development period.

Structure of the Applications to be Developed with the Framework to be Created
Blockchain is a new generation technology that has gained popularity in recent years due to its advantages and the sensation created by cryptocurrencies such as Bitcoin in the financial field. With this popularity, we see that many companies have started to show interest in this technology, they have moved their existing systems to Blockchain technology or developed their new projects based on Blockchain. Unfortunately, it is even seen that some companies force themselves to use Blockchain technology because of this popularity. This creates a very unhealthy situation. Gartner predicted that 90% of the corporate projects started in 2015 using Blockchain technology will fail in 18 to 24 months [12]. The fact that such uncontrolled elections are held with the effect of popularity returns to companies as a waste of time and money. Based on this, it is of great importance to determine the use of the smart contract framework work we have done in the right areas and to prevent such waste of resources. When deciding on application scenarios, HAVELSAN's field of activity and project needs should be taken into consideration, and the benefit/loss analysis should be done correctly.
Before deciding on Blockchain applications, determining the capabilities of the infrastructure on which the application will be developed is an important factor affecting the success of the application. If a closed box Blockchain application that does not need to be integrated with external systems will be developed, the use of Hyperledger Fabric-Cello will be the right choice for ensuring high security. However, if an application to be integrated with external systems is to be developed, the use of Hyperledger Fabric-Cello will not be suitable. As Composer enables and facilitates integration through Rest APIs, the issue of integration with the use of Fabric-Composer will not be a problem anymore. Choosing the appropriate infrastructure is important for developing successful applications. The experiences we have obtained from the problems we encountered during the development phase of the framework support this claim. Therefore, this criterion should be taken into account when determining the framework. In addition, different solution proposals of Hyperledger and Ethereum are tried as proof of concept work to enhance the knowledge about this topic. The results are obtained at the end of all these works.
Correct addressing the two issues described above is a prerequisite for determining the appropriate infrastructure. Therefore, the most appropriate applications that match the field of activity and strategy of HAVELSAN were decided first, and then the infrastructure type and services to be used in the line with these choices were determined. While developing such a Blockchain application framework, it was observed that a high-security, flexible, closed-box system is needed, in which we can adjust the workflow according to customer needs. The products that will meet these needs best are Hyperledger Fabric and Cello. Therefore, it was considered that this would be the most feasible use of this framework.

Conclusion
Blockchain is one of the most popular emerging technologies that HAVELSAN is interested in due to its impressive advantages. HAVELSAN has a wide area of activity, so we decided to develop a smart contract framework that enables the development of applications in different areas instead of developing a single Blockchain-based application. Before moving to the development phase of such a Blockchain-based smart contract framework, the infrastructure used to create our framework had to be determined first. There is an open code or paid services from which the infrastructure service to be used can be obtained. Open source is one of the most preferred cost-effective methods in today's technology age. Open-source service providers are made up of wider audiences. With this broad participation, the service is provided faster and thus, faster solutions to the problems are provided. In addition, applications can be developed with open participation without the need to pay any fees. After evaluating these advantages, we decided to choose an open-source provider. Organizations that are providing such services have been examined. It was decided to use Hyperledger after evaluating the factors such as allowing application development in areas other than cryptocurrencies, having private network structure, and configuration flexibility. As Blockchain is a relatively new technology, we encountered many different problems. Since the number of completed Blockchain projects is limited, the number of articles and other resources in the literature is also very low, making it difficult to quickly find solutions to problems encountered during the development phase. It could be predicted that this problem will be eliminated as the number of completed projects in literature is increased. Another problem encountered is; concerns the display of blocks to users. We can say that we had a problem showing detailed information about the newly added block. Data on the network created by Hyperledger Fabric is kept in a closed box structure with high security. In this structure, it is possible to access the data on the blocks only with the commands provided by Fabric. Due to this restriction, limitations are encountered in accessing block data through the developed application layer. To avoid this uncertainty, we had to research how detailed information about the blocks could be shown. We wrote different functions from the display layer of the data for detailed access to the data on the layer on which it was kept. Maybe the most important problem that has encountered during the development of the application is about integration abilities. Although it is possible to create high security, flexible, modular closed box Blockchain network suitable for customer needs by using Hyperledger Fabric and Cello tools, there are shortcomings in terms of integration with external systems. If there is a need for such an external system integration, the use of Hyperledger Fabric-Composer would more suitable. It makes it easier to integrate with Rest API with other systems. Besides all the problems encountered, it is to decide which type of framework to build as a result of our studies on another subject evaluated. If there is no need to integrate the applications to be developed with external systems, the use of Hyperledger Fabric-Cello may be preferred, but if there is a need for integration with external systems, the use of Hyperledger Fabric-Composer needs to be determined. A serious effort was made to overcome all these problems, different proof of concept work was completed. However, important experiences were obtained at the end. All these were obtained while generating HAVELSAN Smart Contract Framework. In the coming period, it is planned to develop different applications using this developed smart contract infrastructure. Thus, the accumulated knowledge can be further increased.