Search code examples
hyperledger-fabrichyperledgerhyperledger-chaincodechaincode

Getting Chaincode from NodeJS


On Ethereum, by inspecting a transaction on EtherScan, you are able to see the public chaincode used for that transaction.

I would like to see the chaincode used for the transaction, or maybe retrieve the current chaincode instantiated on the channel. Is it possible, maybe from the SDK, to retrieve the code of the Hyperledger Contract and return it via API?


Solution

  • Ethereum is a public blockchain platform. On the other hand, Hyperledger Fabric is a private and permissioned blockchain platform.

    It makes sense to be able to see the public smart contract used for a transaction in the case of Ethereum but the same concept doesn't apply to Hyperledger Fabric. A chaincode(smart contract) is a piece of code that is installed and instantiated through an SDK or CLI onto a network of Hyperledger Fabric peer nodes, enabling interaction with that network’s shared ledger.

    You can call the chaincode APIs available to you like query, invoke, get history for a key, etc through SDK or CLI, but you can't get the entire code of chaincode.

    Try to understand in this way. In a traditional app, you've your backend service and your frontend service, and they may run on the same or different servers. The frontend is able to interact with your backend service generally through the means of Rest APIs but does backend service ever allow you to see the entire codebase of it? Never.

    The same concept applies here as well. Though the chaincode package is signed by every organization's member who is involved, and that is done to keep transparency in the network.

    Also, I don't think there'll come any scenario where being able to see the chaincode from SDK or CLI would become crucial. The access to the chaincode codebase should be limited and the authorized member of the concerned organizations always have access to it.