Skip to content
Related Articles
Open in App
Not now

Related Articles

What is Chaincode in Hyperledger Fabric?

Improve Article
Save Article
Like Article
  • Difficulty Level : Hard
  • Last Updated : 28 Jul, 2022
Improve Article
Save Article
Like Article

Blockchain is the technology that has been making a lot of news lately. It’s a hot topic because it’s believed to be revolutionary by many. Hyperledger Fabric is one of the leading blockchain frameworks out there, and this article will explain what Chaincode is within Hyperledger Fabric. The following topics will be discussed here:

  1. What is Chaincode In Hyperledger Fabric?
  2. Types of Chaincode In Hyperledger Fabric?
  3. System Chaincodes
  4. Chaincodes For Developers In Blockchain
  5. Chaincodes For Operators In Blockchain
  6. Conclusion

Let’s start discussing each of these topics in detail.

What is Chaincode in Hyperledger Fabric?

A Chaincode (or “smart contract”) is an application that runs on top of the underlying architecture to enforce business rules and maintain the state. This application can define its own data structures, or use the types of services exposed by other chain codes running in parallel on the same peer node.

  • The node that participates in the consensus protocol validates blocks and distributes them to other peers. Each node has access to all information required for this task and runs an internal chaincode that enforces business rules.
  • Chaincode is the program that is running on a peer node.
  • There are many chaincodes out there and they all run the same way, enforcing business rules on transactions. 
  • Chaincode can be written in any language supported by the underlying platform. 

Types of Chaincodes in Hyperledger Fabric

In Hyperledger Fabric, there are two different types of chaincodes:

  • Orderer Chaincode: This type of chaincode is executed by an orderer node (a peer with special tagging configured in the network identity). The orderer executes this chaincode for each transaction and subsequently enforces the business logic associated with this transaction by representing it as an “Order” object. The order is then sent to the participants in the peer-to-peer network (“Peer”) and they are responsible for processing it (as long as they confirm that the transaction is valid). This type of chaincode is executed by an orderer node (a peer with special tagging configured in the network identity). The orderer executes this chaincode for each transaction and subsequently enforces the business logic associated with this transaction by representing it as an “Order” object. The order is then sent to the participants in the peer-to-peer network (“Peer”) and they are responsible for processing it (as long as they confirm that the transaction is valid).
  • Core Chaincode: This type of chaincode is executed by a core node (a peer that runs multiple chaincodes). The core node has special tagging configured in the network identity. The core node executes this chaincode for each transaction but represents it as a new message that is sent using the Messaging service. As mentioned above, chaincode will run on the peer nodes within the Hyperledger Fabric network. When running a chaincode, there are several things that will be enforced on transactions by chaincode. A peer group can be seen as a logical cluster of peers that are connected to each other through a leader. Each peer in this group will be running the chaincode of the same type.

What are System Chaincodes?

  • A system chaincode is a set of functions that provides the blockchain runtime with information about the status of a transaction, while still allowing the transaction to execute. It can be used to validate or reject transactions, or to obtain additional information about Blockchain interactions.
  • In Hyperledger Fabric, system chaincodes are usually written in a programming language based on Javascript (e.g., Nodejs) and run in a container as an isolated process. A developer can write custom application-specific chaincodes by using one of many available SDKs for systems programming languages such as C++, Go, Rust and Python.
  • Hyperledger Fabric is a blockchain-based distributed ledger with a modular architecture, which is, in general, compatible with Hyperledger Fabric. 
  • There are several organizations that provide support for the Hyperledger Fabric project, and Hyperledger is one of the key contributors to this effort.
    It is said to be an open-source distributed ledger framework designed by the Linux Foundation. 
  • It has been inspired by the Bitcoin Blockchain as well as the  Ethereum Platform and its purpose is to have an open source blockchain system in which each participating enterprise can design and build their own custom applications to interact with the blockchain “to improve their operational processes or business model”. 

Chaincode For Developers in Blockchain

Chaincode is a program that lives in the blockchain and it executes transactions when instructed. It offers an alternative to using scripts to create smart contracts. 

  • Chaincode is written in Javascript which allows developers without a background in crypto economics to understand the codebase and use it in their applications.
  • Chaincode for developers has been pioneered by Hyperledger Fabric, an open-source framework from Linux Foundation that implements a blockchain architecture with permission ledgers and multi-party computation (MPC). 
  • As per the spec, chaincode will be used for “stateful business logic”, which does not require any state change by a consensus algorithm.
  • Chaincode is code that is invoked by participating nodes in order to validate transactions that are part of a block’s blockchain; it can also invoke other transaction types like event subscription or coinbase transactions. Chaincodes also execute scriptable data-management operations on the blockchain’s state database.
  • Chaincode is also referred to as smart contracts due to its ability to interact with the blockchain and perform data manipulation functions.
  • Several different types of chaincodes are available from Coda Blockchain’s Smart Contracts Library, including oracle, multisignature, timestamping, and Keystore. Coda also provides various coinbase operations for creating/composing transactions that include transaction value and identifying remarks on the blockchain.
  • As a means of simplifying development on the blockchain and facilitating interop with legacy systems, Coda provides a number of features such as the use of native libraries like libevent in order to provide access to APIs like libbitcoin or libledger

Chaincode For Operators

Chaincode is a fabric-specific script written to perform operations within the framework. Hyperledger Fabric’s chaincode enables a user with no knowledge of blockchain technology to build and deploy smart contracts and transactions. 

  • These scripts can be defined as executable pieces of software that act on input data generated by other code.
  • The chaincode creates and runs transactions using consensus across nodes in the decentralized system; this helps to enforce the rules set within entities’ business logic while taking into account all contributions from other participants in the network, known as actors. 
  • This includes both transactions between actors, such as customers or suppliers, but also interactions with fabric-specific functions like transaction ordering or reconciliation.
  • Within the context of blockchain development, smart contracts also refer to contract code that is enforced by the distributed blockchain ledger and executed automatically when a condition specified in the contract code is triggered. 
  • In this context, smart contracts are executable programmable logic (programs) that are stored on the blockchain, which can only be run by authorized parties. For operators, they can be used as a means of upgrading their distributed ledger systems to provide new functionalities, such as allowing users to issue assets and make transactions with them.
  • Chaincode provides an interface for smart contracts to be programmed via Chaincode. Coda’s Chaincode performs the following functions:
  • Chaincode is launched in one of two ways in Coda: Either by invoking it via the CLI or programmatically via SDK calls. In order for the node operator to launch chaincode, one must first authorize launch permissions by providing a list of node IDs for which the chaincode is authorized to run.
  • Chaincodes should primarily be written using Go, but other languages such as Python and NodeJS can also be used.


In chaincode, we have seen that blocks are represented as transactions, and peers are grouped into peer groups that are interconnected through a leader peer. There will be some different types of transactions generated in Hyperledger, and these different types can have the same concept of a block where the transactions of the same type all go into a block. A transaction is a message sent by an external source (for example, an API call or other external messaging service), which contains certain values. If a transaction is being processed by another peer group (peer group for business rules) or core node(Core node for messages sent from other peers or as part of messages), then we say that transaction is being put into a block.

My Personal Notes arrow_drop_up
Like Article
Save Article
Related Articles

Start Your Coding Journey Now!