Re: Getting block height -Fabric-sdk-jAVA #fabric-sdk-java

Mark Lewis

You should be able to use evaluateTransaction() to invoke the GetChainInfo transaction function on the qscc system chaincode. The response will be a serialized BlockchainInfo protocol buffer object, which can be deserialized, and has (amongst other things) the block height.

Something along the lines of:

Contract qscc = network.getContract("qscc");
byte[] result = contract.evaluateTransaction("GetChainInfo");
Ledger.BlockchainInfo info = Ledger.BlockchainInfo.parseFrom(result);
long blockHeight = info.getHeight();

Bear in mind that this is the current block height of whichever peer evaluated the transaction. Other peers may have different block heights at that point in time.

Join to automatically receive all group messages.