Hyperledger Fabric: Get Block Data for all blocks

Viewed 369

I just set up a Hyperledger Fabric network (2.2) with chaincode(node js) for me and my team.

We are using Hyperledger SDK for NodeJS (Version 2.2) for network interaction.

Now the problem is, we need to query block data for all transactions in the network.

How can we get all existing blocks and query them?

With SDK 1.4, there was channel.getBlockbyTXid().

Is there a solution for the newest SDK Version?

1 Answers

Use the QSCC Chaincode and invoke functions like GetBlockByNumber and GetTransactionByID.

Example

      const network = await gateway.getNetwork("mychannel");
      const contract = network.getContract("qscc");

      let result = await contract.evaluateTransaction("GetBlockByNumber", channelName, blkNum);
      // or
      let result = await contract.evaluateTransaction("GetTransactionByID", channelName, txId);

Related