Reputation: 174
I am trying to build a decentralized app that able to do show the block header like data hash, the previous hash of the block when a user submits a new transaction. However, It seems like the new version of Fabric Node SDK 2.2 removes the function queryblock.
I refer on the documentation at https://hyperledger.github.io/fabric-sdk-node/release-2.2/module-fabric-network.html and currently still looking for some workaround to show the block info of the user's transaction.
The ideal output that I wish to achieved is almost similar to what Hyperledger Explorer provide.The reference can be check at:
which show the information such as Number of Blocks, Data Hash, Previous Hash and other Block Information regarding the hash.
There are some information like BlockEvent that have the name blockData
in the interface BlockEvent
. However, I can't seem to find it when npm install i fabric-network
.
Since the user can query and check their hash with the ledger, a key or hash need to be returned to the user upon transaction success. Is there any API function for this? So far, I able to found there are getTransactionId()
in the class Transaction
. But is this one that I need to use?
All of the reference since to deal with the old version of node SDK which is version 1.4.
Upvotes: 3
Views: 1887
Reputation: 336
You can query block number by call function GetBlockByNumber
of qscc
contract. Example:
const contract = network.getContract('qscc');
const resultByte = await contract.evaluateTransaction(
'GetBlockByNumber',
channelName,
String(blockNum)
);
const resultJson = BlockDecoder.decode(resultByte);
logger.debug('queryBlock', resultJson);
Upvotes: 2