Spring Boot Fullstack Blockchain Application With Hyperledger Fabric running on Kubernetes (Part 1) — Introduction

Şuayb Şimşek
7 min readOct 17, 2021

Hello everyone, through this article series we will the Hyperledger Fabric integration with Spring Boot.In this article, we will look into Spring Boot Hlf Starter introduction , Asset Transfer Application introduction,Blockchain and Hyperledger Fabric concept.In other articles we will implement Asset Transfer Application step by step and deploy this app on Kubernetes.In the next articles,I will also explain Hyperledger explorer, grafana integration on Kubernetes.

Other articles on Hyperledger Fabric integration with Spring Boot can be accessed from the links below.

Part 1 — Introduction

Part 2 — Kubernetes Cluster Setup

Part 3 — Fabric CA Server

Part 4 — Generating Certificates and Artifacts

Part 5 — Kafka

Part 6 — Orderer

What is Asset Transfer App?

Asset Transfer Application is a blockchain based fullstack application that allows you to create and transfer an asset by putting data on the ledger and retrieving it.The chaincode part of the application is written in Go, the backend part is written in Spring boot, and the frontend part is written in Angular.

Project details and installation of Asset Transfer Application can be accessed via this link

What is Spring Boot Hlf Starter?

Spring Boot Hlf Starter library is a spring boot starter library I wrote.This library provides an easy way to get your Spring boot application using Hyperledger Fabric Gateway SDK v2.2 up and running quickly.

Spring Native provides support for compiling Spring applications to native executables using the GraalVM native-image compiler.I’m thinking of adding spring native support in the next versions of the project.

Project details and installation can be accessed via this link

What is Blockchain?

It was made with the work done by Stuart Haber and Scott Stornetta, who were in the cryptographic development phase of blockchain technology in the 1990s. Starting from the concept of the “hash tree”, which was classified in a way in the 1970s, two experts have managed to approach its definition with the modern blockchain, in full terms. Not Satoshi Nakamoto, but Haber and Stornetta.

The first Blockchain in its current sense is as old as Bitcoin, the first cryptocurrency in history. When the calendars showed October 31, 2008, the white paper document called “Bitcoin: Peer-to-Peer Electronic Cash System” published by a person or group named Satoshi Nakamoto stated that the BTC infrastructure was completely based on blockchain technology.

How Blockchain Works?

Blockchain, which has a very wide working area, is used. Blockchain can be made from authorized and unofficial use cases, from usage areas, from contracts to notary transactions.

The most important features underlying the working principle of blockchain technology; it is anonymous, distributed, decentralized and public, yet unbreakable and unhackable. The fact that an information record chain is both accessible and unbreakable to everyone causes everyone, especially computer scientists, to approach this technology with admiration. There is a simple logic behind the fact that the records committed to the blocks are unbreakable and unchangeable: All blocks in this registry, which has billions of copies, must be changed in order to corrupt the blocks. It is almost impossible to make such an intervention.

What is Ethereum?

Ethereum is an open source distributed public blockchain network. It allows decentralized apps to be built on it with the help of Smart Contract functionality.

Vitalik Buterin developed Ethereum as an extension to the original core blockchain concept. He improvised Bitcoin’s protocols to support applications beyond currency issuance. Its major breakthrough is the ability to easily write and deploy Smart Contracts. These are actually bits of code that are executed on the network. Hence, this platform could help developers to write programs for building decentralized organisations.

What is Hyperledger Fabric?

Hyperledger Fabric is a framework for developing Blockchain-based solutions for the enterprise. It is open-source and under the umbrella of the Linux Foundation.It is a private chain, thus super-helpful for enterprises since you don’t want to put your transactions for public display.The framework has a very sophisticated module architecture which allows thedeveloper to design the blockchain network with security, scalability, confidentiality and with high performance.

Hyperledger Fabric vs Ethereum

The subject of this article is not etherium. so I won’t explain ethereum in detail. The differences between Ethereum and Hyperledger Fabric are explained in the table below.

What is DLT?

Any Blockchain works on top of a DLT, or Distributed Ledger Technology. DLTs are protocols to store all transactions that take place in a network. In a Blockchain protocol, the network is decentralized, which means that the transaction history is replicated across all the participating nodes.

The Architecture of Fabric

Fabric is a permissioned Blockchain, it has certain protocols you might not have heard of before, it’s time to take a look at them.

Ledger

In Hyperledger fabric ledger is a transaction history log that contains the state of each transaction committed to the ledger. The ledger consists of two parts World State, Blockchain.

World State — It’s a database that contains the updated records for a transaction. The World state gets more comfortable for the programmer to check the record is stored accurately into the ledger or not.Hyperledger fabric supports LevelDB and CouchDB as the state database.I used CouchDB in Asset Transfer Application.

Blockchain — is a set of sequential blocks containing the sequence of transactions carried out in the world state. Hyperledger Fabric uses an ordering service for transaction sequencing within the blocks.

Transaction

The role of a transaction is to store the state of an object.

Blocks

Blocks In Blockchain the first block is called the genesis block. This initial block doesn’t contain any user transaction but stores the channel configuration in the network.

Peers

Peers are a fundamental unit of any distributed model. Peers are essentially nodes, but in public blockchain networks like Bitcoin or Ethereum, all peers are equal. In a private Blockchain, all peers are not equal.

In Asset transfer application, each organization has only 1 peer.

The Consensus Mechanism

The point of Consensus is validating the correctness of a Block, and that it adheres to the policies set by the Chaincode. There are 2 types of Consensus Mechanisms in Fabric: Voting and Lottery. Voting is the more accepted method in enterprise right now. You, as a developer, must develop your Fabric-based enterprise application on the idea that there is partial trust in a network. I hope Voting and Lottery are clear from their nomenclature as to what they do, if not, refer to the official docs.

Consensus in Fabric is broken down in three phases:

  1. Endorsement: The participants will have to endorse a transaction.
  2. Ordering: This phase will agree to the order of commitment to the ledger.
  3. Validation: Validates structure and order.

Chaincode

Chaincode is the software that defines the asset. Assets are basically a key-value pair, where Asset definitions enable the exchange of almost anything with a monetary value over the network. Chaincode is a program that runs in a secured Docker container. Chaincode is the Smart Contract of Fabric in the sense it runs the business logic of the network. You can write ChainCodes in Go, NodeJS, or Java.The chaincode part of Asset transfer application is written in Go.

Asset transfer application has a single chaincode called basic.

Organization

This is a set of groups of members under a single MSP. An organization can be related to a big multi corporation group or small coffee shop. The naming convention for organization MSP can be derived as Org1.MSP, here organization is “Org1”. And also an organization can have many MSPs based on its requirements.

Asset transfer application has 3 organizations.Org1,Org2,Org3.

Membership Service Provider (MSP)

For clients to participate in a private network, they need credentials to be authentic. MSPs are an abstract component that provides credentials to the clients. Clients use these credentials to authenticate their transactions, and peers use these credentials to authenticate transaction processing results (endorsements).

Channels

Hyperledger Fabric has a technique that allows the organization to join multiple blockchain networks through a channel. So, multiple organizations can communicate or participate in many networks implementing various channels.Asset transfer application has a single channel called mychannel.

What is Hyperledger Explorer?

Hyperledger Explorer is a simple, powerful, easy-to-use, well maintained, open source utility to browse activity on the underlying blockchain network. Users have the ability to configure and build Hyperledger Explorer on MacOS and Ubuntu.

In the next articles, I will explain the integration of Hyperledger Fabric with Hyperledger Explorer.

My article ends here. In general, I tried to give theoretical information about Hyperledger Fabric,Hyperledger Explorer and Blockchain.

See you in the next articles.

Project Links

Spring Boot Hlf Starter Project details and installation can be accessed via this link.

Asset Transfer Project details and installation can be accessed via this link

--

--

Şuayb Şimşek

Software Engineer at Community Gaming . #Java #Kotlin .#Devops . #Blockchain . #SpringBoot . #Echo .#Golang .#React