getChainHeader method

Future<int> getChainHeader({
  1. BlockHash? at,
})

Get the latest block number or specific block number by BlockHash.

Implementation

Future<int> getChainHeader({BlockHash? at}) async {
  final List<String> params = <String>[];
  if (at != null) {
    params.add('0x${hex.encode(at)}');
  }
  final response = await _provider.send('chain_getHeader', params);

  if (response.error != null) {
    throw Exception(response.error.toString());
  }
  return int.parse(response.result['number']!);
}