-
Notifications
You must be signed in to change notification settings - Fork 2
Get BlockChain info
Wei Hau Lim edited this page May 12, 2022
·
5 revisions
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');
}
}- 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');
}- 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');
}- 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');
} try {
final result = await client.blockChain.getDiagnosticStorage();
print(result);
} on Exception catch (e) {
print('Exception when calling BlockChain->GetDiagnosticStorage: $e\n');
} try {
final result = await client.blockChain.getBlockchainScore();
print(result);
} on Exception catch (e) {
print('Exception when calling BlockChain->GetBlockchainScore: $e\n');
}