Basic knowledge of hyperledger fabric
In this article, we will introduce the basics of hyperledger fabric and learn how to make full use of this multi-functional blockchain framework.
Blockchain technology provides abundant opportunities for innovation. It provides a new way of transaction, which can fundamentally change the realization of business.
So, among the numerous blockchain frameworks, which framework should developers master first? Hyperledger fabric developed by IBM is definitely the best choice, especially in today’s uncertain public chain application, using fabric to develop alliance chain should be the most common and practical framework.
Hyperledger is an open source collaboration achievement, which aims to promote cross industry blockchain technology for enterprises to use. The global collaboration is hosted by the Linux foundation.
Hyperledger incubates and supports a range of blockchain business technologies, frameworks, libraries and applications. The hyperledger project hosts several blockchain frameworks, including hyperledger fabric. This article outlines what hyperledger fabric is, how to use it to build solutions, and how to execute transactions in hyperledger fabric.
What is hyperledger fabric?
Hyperledger fabric is an open source framework implementation for private chain and alliance chain business networks, in which membership and roles are known to other members. It is a modular architecture. It allows components such as ledger database, consensus mechanism and membership service to plug and play. It uses container technology to provide enterprise level network security, scalability and confidentiality.
Hyperledger fabric network has the following components:
- Assets。 Assets are anything of value. Assets have status and ownership. Assets are represented in hyperledger fabric as a collection of key value pairs.
-
Shared ledger。 Shared ledgers record the status and ownership of assets. The shared ledger consists of two parts
- World state describes the state of the shared ledger at a given point in time. This is a database of shared ledgers.
- Blockchain is a transaction log history that records all transactions.
- Smart contract。 The hyperledger fabric smart contract is called chaincode. Chaincode is the software that defines assets and related transactions; in other words, it contains the business logic of the system. Chaincode is called when the application needs to interact with the shared ledger. The chain code can use golang or Node.js to write.
- Peer nodes。 Peer is an essential element of the network because they host shared ledgers and smart contracts. Peer executes chain codes, accesses shared ledger data, recognizes transactions, and interfaces with applications. Peer can be endorsing peers or endorsers. Each chain code can specify an endorsement policy, which defines the necessary and sufficient conditions for effective transaction endorsement.
- Channel。 Channel is a logical structure formed by peers set. This function allows a group of peers to create a separate transaction shared ledger.
- Organizations。 Hyperledger fabric network is constructed by peers owned and contributed by different organizations in the network. The network exists because the organization contributes its personal resources to the collective network. Peers have the identity (digital certificate) assigned by the membership service provider from its organization. Peers of different organizations can be on the same channel.
- Membership Services Provider (MSP)。 MSP is a certification authority to manage certificates used to authenticate memberships and roles. In the hyperledger fabric network, all nodes must have an authenticated identity to trade. MSP manages user IDs and validates all participants on the network, making hyperledger fabric a private and accessible network.
- Ordering service。 Ordering service packages the transaction into blocks to deliver to peers on the channel. It ensures the smooth execution of transactions in the network. It communicates with peers and endorsing peers. Currently, ordering service only supports solo and Kafka.
The following figure shows the components and composition of hyperledger fabric
How does the hyperledger architecture work?
In the hyperledger solution, the hyperledger fabric network acts as the back end, while the application front end communicates with the network. The SDK helps you establish communication between the front end and the back end, such as Node.js SDK and Java SDK. SDK provides a method to execute user chain code, execute transaction and monitor events in the network.
To write a blockchain application, you need to:
- Write the chaincode in a supported programming language, such as go.
- Deploy chain code on hyperledger fabric network.
- Using SDK to develop client applications.
How to execute hyperledger transaction
The transaction request flow in the hyperledger fabric network is as follows:
- Client use Node.js Or Java ™ The SDK connects to the hyperledger fabric network. The client uses the SDK API to create a transaction and send it to the endorser.
- Endorsing peer will verify the customer’s signature, simulate the transaction and send endorsement signature.
- If the transaction is approved, the customer submits the transaction to the ordering service. Otherwise, the transaction is cancelled.
- The ordering service passes the transaction to peers. All peers commit and apply the same transaction sequence and update its status.
summary
Hyperledger fabric is a blockchain framework implementation. You can easily use hyperledger to build a private or federated network and write smart contracts for it.
Of course, hyperledger is more complex than other blockchain frameworks because it is designed for enterprise applications. We will explain it in detail later.
For more tutorials, please refer to flydean’s blog