Skip to content

Get BlockChain info

Wei Hau Lim edited this page May 12, 2022 · 5 revisions

Get the current height of the chain

import 'package:xpx_chain_sdk/xpx_sdk.dart';

const baseUrl = 'http://bctestnet3.brimstone.xpxsirius.io:3000';

/// Creating a client instance
/// xpx_chain_sdk uses the Dart's native HttpClient.
/// Depending on the platform, you may want to use either
/// the one which comes from dart:io or the BrowserClient
/// example:
/// 1- import 'package:http/browser_client.dart';
/// 2- var client = newClient(config,  BrowserClient());
final client = SiriusClient.fromUrl(baseUrl, null);

/// Simple BlockChain API request
void main() async {
  /// Get the current height of the chain.
  try {
    final result = await client.blockChain.getBlockchainHeight();
    print(result);
  } on Exception catch (e) {
    print('Exception when calling BlockChain->GetBlockByHeight: $e\n');
  }
}

Get BlockInfo for a given block height

  • Following parameters required:
    • Height - height of block to get info from in Uint64
  try {
    final height = Uint64.fromInt(1);
    final result = await client.blockChain.getBlockByHeight(height);
    print(result);
  } on Exception catch (e) {
    print('Exception when calling BlockChain->GetBlockByHeight: $e\n');
  }

Get an list of BlockInfo for a given block height and limit

  • Following parameters required:
    • Height - height of block to get info from in Uint64
    • Limit - how many block infos to return starting from height
  final height = 1;
  const limit = 50;

  try {
    final result =
        await client.blockChain.getBlocksByHeightWithLimit(height, limit);
    print(result);
  } on Exception catch (e) {
    print(
        'Exception when calling BlockChain->GetBlocksByHeightWithLimit: $e\n');
  }

Get transactions from a block

  • Following parameters required:
    • Height - height of block to get transactions from in Uint64
  final height = Uint64.fromInt(1);
  try {
    final result = await client.blockChain.getBlockTransactions(height);
    print(result);
  } on Exception catch (e) {
    print('Exception when calling BlockChain->GetBlockTransactions: $e\n');
  }

Get the storage information

  try {
    final result = await client.blockChain.getDiagnosticStorage();
    print(result);
  } on Exception catch (e) {
    print('Exception when calling BlockChain->GetDiagnosticStorage: $e\n');
  }

Get the current score of the chain

  try {
    final result = await client.blockChain.getBlockchainScore();
    print(result);
  } on Exception catch (e) {
    print('Exception when calling BlockChain->GetBlockchainScore: $e\n');
  }

Clone this wiki locally