Blockchain Application development-II (Hyperledger Fabric)

Blockchain Application development-II (Hyperledger Fabric)

Hyperledger fabric

  1. Hyperledger Fabric platform is an open source blockchain framework hosted by The Linux Foundation. It has an active and growing community of developers.

  2. It is a modular, general-purpose framework that offers unique identity management and access control features, which make it suitable for a variety of industry applications such as track-and-trace of supply chains, trade finance, loyalty and rewards, as well as clearing and settlement of financial assets.

  3. A Hyperledger Fabric network is comprised of unique organizations (or members) that interact with each other on the network.

Hyperledger Fabric Architecture

  1. Hyperledger Fabric is an open-source platform for building distributed ledger solutions, with a modular architecture that delivers high degrees of confidentiality, flexibility, resiliency, and scalability. This enables solutions developed with fabric to be adapted for any industry.

  2. The Hyperledger Fabric architecture delivers the following advantages-

  • Chaincode trust flexibility : The architecture separates trust assumptions for chaincodes (blockchain applications) from trust assumptions for ordering.

  • Scalability - As the endorser nodes responsible for particular chaincode are orthogonal to the orderers, the system may scale better than if these functions were done by the same nodes.

  • Confidentiality : The architecture facilitates deployment of chaincodes that have confidentiality requirements concerning the content and state updates of its transactions

  • Consensus modularity - The architecture is modular and allows pluggable consensus implementations.

  1. The architecture consists of several key components, including:
  • Peers: These are the nodes in the network that participate in the consensus process and maintain a copy of the ledger.

  • Chaincode: This is the smart contract component of Hyperledger Fabric. Chaincode is responsible for implementing the business logic of the blockchain application.

  • Ordering Service: This component is responsible for ordering transactions and broadcasting them to peers for endorsement and validation. Membership Service Provider (MSP): This component is responsible for managing the identities of the participants in the network. It ensures that only authorized entities can access the network and participate in transactions.

  • Ledger: The ledger stores all the transactions that have been executed on the network. It is a distributed ledger, meaning that all peers have a copy of it.

  • Client: The client is responsible for interacting with the network. It can be a user or an application that submits transactions to the network, queries the ledger, and receives responses.

Hyperledger Fabric, identities and policies

  1. In Hyperledger Fabric, identities and policies play an important role in managing access to the network and controlling who can perform certain actions.

  2. Identities: Identities in Hyperledger Fabric are used to represent the participants in the network, such as users, organizations, and applications. Each identity is associated with a unique digital certificate, which is used to authenticate the identity and provide proof of its identity. These digital certificates are issued by a Membership Service Provider (MSP), which is responsible for managing the identities in the network.

  3. Policies: Policies in Hyperledger Fabric are used to control access to the network and define who can perform certain actions. Policies are defined in the form of access control rules and can be applied to different components in the network, such as chaincode, channels, and ledger. These rules are used to restrict access to certain parts of the network to specific identities or groups of identities.

  4. For example, a policy can be defined to allow only certain identities to submit transactions to the network, or to restrict the ability to query the ledger to a specific group of identities.

Hyperledger fabric, transaction validation

  1. In Hyperledger Fabric, transaction validation is the process of ensuring that a proposed transaction is valid and complies with the rules defined by the network.

  2. This process is performed by the peer nodes in the network, which act as validators. When a transaction is submitted to the network, it is first broadcast to a set of endorsing peers.

  3. These peers are responsible for endorsing the transaction, which means that they execute the chaincode associated with the transaction and return a proposal response. The proposal response contains the results of the chaincode execution and a digital signature from the endorsing peer, which attests to the validity of the transaction.

  4. Once the endorsing peers have returned their proposal responses, the client then submits the transaction, along with the proposal responses, to the ordering service.

  5. The committing peers are responsible for validating the transactions. They check that the transactions are properly endorsed, that the digital signatures from the endorsing peers are valid, and that the transactions comply with the network policies.

  6. In summary, transaction validation in Hyperledger Fabric is a multi-step process that involves endorsement by endorsing peers, ordering and validation by the ordering service and committing peers, and update of the ledger by the committing peers.

  7. This process helps to ensure that only valid transactions are executed on the network and that the ledger remains consistent and tamper-proof.

Writing smart contract using Hyperledger Fabric

Here is a step-by-step procedure to write a smart contract using Hyperledger Fabric:

  1. Setup the development environment: Before you can start writing the chaincode, you'll need to have a development environment set up. This includes installing the Hyperledger Fabric binaries and Go programming language, as well as any other necessary dependencies.

  2. Create a new chaincode project: Create a new directory for your chaincode project and initialize it as a Go module. You can also use an existing starter chaincode project as a template.

  3. Implement the chaincode: This is the main step where you'll implement the business logic of your smart contract. You'll need to define the chaincode's Init and Invoke functions, as well as any other functions that are needed to implement the logic.

  4. Test the chaincode: Once you've implemented the chaincode, you'll need to test it. You can use the Hyperledger Fabric chaincode test tool, which allows you to test the chaincode locally without the need for a network.

  5. Package the chaincode: Once you've tested the chaincode and are satisfied with the results, you'll need to package it so that it can be deployed to the network. This typically involves creating a .tar file that contains the chaincode and any other necessary files.

  6. Deploy the chaincode: Once the chaincode is packaged, you can deploy it to the network. This typically involves using the Hyperledger Fabric command line tools to install and instantiate the chaincode on the network.

  7. Interact with the chaincode: Once the chaincode is deployed, you can interact with it by submitting transactions and querying the ledger. You can use the Hyperledger Fabric SDKs to interact with the chaincode from your application.

Writing smart contract using Ethereum

  1. Setup the development environment: Before you can start writing the smart contract, you'll need to have a development environment set up. This includes installing a local Ethereum blockchain client, such as Geth or Parity, as well as a development framework, such as Truffle. You'll also need to be familiar with the Solidity programming language, which is used to write smart contracts on the Ethereum platform.

  2. Create a new project: Create a new directory for your smart contract project and initialize it with Truffle. Truffle is a development framework that provides a suite of tools for writing, testing, and deploying smart contracts on the Ethereum blockchain.

  3. Write the smart contract: This is the main step where you'll write the business logic of your smart contract using the Solidity programming language. You'll need to define the contract's variables, functions, and events, as well as any other necessary logic.

  4. Test the smart contract: Once you've written the smart contract, you'll need to test it. You can use Truffle's built-in testing framework to test the smart contract locally without the need for a network.

  5. Deploy the smart contract: Once you've tested the smart contract and are satisfied with the results, you'll need to deploy it to the Ethereum network. This typically involves using Truffle to compile and deploy the contract to a local or remote Ethereum blockchain.

  6. Interact with the smart contract: Once the smart contract is deployed, you can interact with it by calling its functions and querying its state. You can use Truffle or web3.js library to interact with the smart contract from your application.

Overview of Ripple and corda

  1. Ripple and Corda are both distributed ledger technologies that are designed for financial applications, but they have some key differences in their architecture and use cases.

  2. Ripple is a real-time gross settlement system, currency exchange and remittance network created by Ripple Labs Inc., a US-based technology company.

  3. Ripple is designed to enable fast, low-cost international money transfers. It uses a consensus algorithm called the Ripple Protocol Consensus Algorithm (RPCA) to validate transactions.

  4. Ripple also has its own digital asset called XRP, which is used as a bridge currency to facilitate cross-border payments and to help prevent the double spending of other assets.

  5. Corda is an open-source distributed ledger platform developed by R3, a consortium of financial institutions.

  6. Corda is designed to enable financial institutions to transact directly with each other without the need for a central intermediary.

  7. It uses a consensus algorithm called the Corda consensus algorithm, which enables participants to reach agreement on the state of the ledger without the need for a central intermediary.

  8. Corda is built with a focus on privacy and security, and it uses smart contracts to automate legal agreements between parties.