hejte
hejte

Reputation: 21

Hyperledger Fabric: Get Block Data for all blocks

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?

Upvotes: 1

Views: 1260

Answers (1)

Aditya Joshi
Aditya Joshi

Reputation: 1053

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);

Upvotes: 4

Related Questions