getBlock method

Future<Block> getBlock({
  1. required String blockHash,
})

Get block by hash

Implementation

Future<Block> getBlock({required String blockHash}) async {
  try {
    var response = await sendMessage(
            formatRequest(method: 'getBlock', params: [blockHash]))
        .then((Map<String, dynamic> data) {
      if (data.containsKey('result')) {
        return data['result'];
      } else if (data.containsKey('error')) {
        throw NodeException.fromJson(data['error']);
      }
    });
    return Block.fromJson(response);
  } on NodeException catch (e) {
    throw NodeException(
        code: e.code, message: '{"getBlock": "${e.message}"}');
  }
}