Hyperledger Fabric smart contract package requirements

Hyperledger Fabric (“Fabric”) chaincode can be compiled by multiple programming languages, including Golang, java, and node.js. Each chaincode program must implement a chaincode interface which usually consists of three basic functions: Init, Invoke, and Query.

  • Init: This function is called during the chaincode instantiation and its purpose is to prepare the ledger for future requests. This function must be implemented in all chaincodes.

  • Invoke: The Invoke function is called for all future requests from the off-BSN systems towards the DApps. Here all DApp custom functions or what the DApps can do (for example, to read data from the ledger, to write data in the ledger, to update data, to delete data) are defined. Simply put, Invoke can be understood as an entry point to the chaincode functions. The Invoke function also must be implemented in all chaincodes.

  • Query: The Query function provides a method of querying ledger data. This function can only be used for query purposes and does not offer any operations of ledger data. The Query function is not required to be implemented in all chaincodes.

Note: Fabric 1.4 chaincode package cannot be directly used in Fabric 2.3.2, you need to modify the contract according to the latest chaincode dependencies with the corresponding language.

To realize the automatic deployment of DApp services and to improve deployment efficiency, the following Fabric chaincode packaging requirements have been issued with different programming languages.

1. Golang

The main function must be at the same or higher level as all chaincodes in the project. The zipping path must be the same level folder where the main function is located, and the main function path is the src-based path.

Example: BsnBaseCC Package (the preset chaincode package)


The package should be zipped under BsnBaseCC/ (package name is not required), and the main function path (reference path) is BsnBaseCC.

Example: FabricBaseChaincode chaincode package on github (preset chaincode package)


It should be zipped under github.com/BSNDA/FabricBaseChaincode/chaincode/go/bsnBaseCC/ (package name is not required), and the main function path (reference path) is github.com/BSNDA/FabricBaseChaincode/ chaincode/go/bsnBaseCC.

Description: main.go: the entry; ChainCode: chaincode; models: entities; utils: utilities.

Note: Below is the structure of the Fabric 2.3.2 preset chaincode package


2. Java

gradle or maven-built projects, the projects must contain build.gradle or pom.xml files.

Example: BsnBaseCC package


Package must be zipped under BsnBaseCC/, and there is no requirement for the name of .zip package.

Note: src/main/java: project directory; com.example.javacc: package name; javacc.java: chaincode information

3. NodeJs

package.json file must be built into the project’s root directory. Package needs to be zipped under the directory of BsnBaseCC/. There is no requirement of the name of .zip package.

Example: BsnBaseCC package


Description: marbles_chaincode.js: chaincodes

Note: when publishing DApp services in the BSN portal, chaincode packages should be created in the project’s root directory using .zip format.

© 2019-2021 Red Date (Hong Kong) Technology Limited. all right reserved,powered by GitbookFile Modify: 2022-01-24 16:30:03

results matching ""

    No results matching ""

    results matching ""

      No results matching ""