How to get all existing channels in Hyperledger 1.0 (Node SDK)

Viewed 1557

I am using the Node SDK with Hyperledger 1.0 and want to check if a channel with a specific name exists. Is there a way to query all existing channels? And is there a way to get a channel by name?

1 Answers

You cannot see all available channels, while you can leverage CSCC (Configuration System Chaincode) GetChannels API to get a list of channels client eligible to. You just need to invoke chaincode named CSCC.

The CSCC is the system chaincode, meaning it inherently built in into peer binary and loaded and "instantiate" during peer startup. You can find details here. Considering NodeJS the request will look as following

const request = {
  chaincodeId : "cscc",
  txId: 213213123123, // Some random transaction id
  fcn: "GetChannels",
  args: ['']
}

BTW you also can do it with peer cli:

peer channel list
Related