fetchBlockHeader method

Future<FetchBlockHeaderRes> fetchBlockHeader({
  1. List<int> blockIdBytes = const [],
  2. String blockIdString = "",
  3. CallOptions? options,
})

Returns a FetchBlockHeaderRes object for the block at the given blockId.

blockIdBytes is an List of bytes representing the block ID to retrieve

blockIdString is an String representing the block ID to retrieve

options is an CallOptions for runtime options with RPC

Throws an Exception if block ID validation fails or an error occurs during the RPC request.

Implementation

Future<FetchBlockHeaderRes> fetchBlockHeader({
  List<int> blockIdBytes = const [],
  String blockIdString = "",
  CallOptions? options,
}) async {
  if (blockIdBytes.isEmpty && blockIdString.isEmpty) {
    throw Exception(ErrorMessages.missingBlockId);
  }

  final FetchBlockHeaderReq request = FetchBlockHeaderReq(
      blockId: !blockIdBytes.isEmpty
          ? getBlockIdFromList(blockIdBytes)
          : getBlockIdFromString(blockIdString));
  final FetchBlockHeaderRes response = await nodeStub.fetchBlockHeader(
    request,
    options: options,
  );
  return response;
}