Search code examples
hyperledger-fabrichyperledger

How to get Id number co chaincode of hyperledger fabric by Hyperledger Fabric SDK for node.js?


After I installed the chaincode, the peer chaincode list return all installed chaincode with the id numbers:

peer chaincode list --installed -C mychannel                                                                                                                                         
Get installed chaincodes on peer:
Name: dev-mychaincode-cc, Version: alpha1, Path: /opt/home/mychaincode-cc, Id: 414955ccc11a2644a7f7caxxxb29ee06

Is there anyway to get this id (414955ccc11a2644a7f7caxxxb29ee06) by Hyperledger Fabric SDK for node.js?


Solution

  • You should be able to call the GetInstalledChaincodes transaction function on the lscc system chaincode, and parse the return value, which is a ChaincodeQueryResponse protocol buffer (protobuf) message.

    The protobuf definitions for Fabric are in the fabric-protos repository. There are also published Go, Node (TypeScript/JavaScript) and Java language bindings for all the Fabric protobufs that you can use directly to help unpack protobuf messages:

    https://hyperledger.github.io/fabric-protos/

    For reference, the lscc chaincode's GetAllChaincodes transaction function implementation is here:

    https://github.com/hyperledger/fabric/blob/2b8997153a4d7ea94429b23f9868eb937bce35b5/core/scc/lscc/lscc.go#L613