Skip to content

State API

The State API provides a way to query the state of the blockchain.

Reference

call

Future<Uint8List> call(String method, Uint8List bytes, {BlockHash? at})

Call a contract at a block’s state

getPairs

Future<List<KeyValue>> getPairs(StorageKey prefix, {BlockHash? at})

Returns the keys with prefix, leave empty to get all the keys

getKeysPaged

Future<List<StorageKey>> getKeysPaged({required StorageKey key, required int count, StorageKey? startKey, BlockHash? at})

Returns the keys with prefix with pagination support. Up to count keys will be returned. If startKey is passed, return next keys in storage in lexicographic order.

getStorage

Future<StorageData?> getStorage(StorageKey key, {BlockHash? at})

Returns a storage entry at a specific block’s state.

getStorageHash

Future<BlockHash?> getStorageHash(StorageKey key, {BlockHash? at})

Returns the hash of a storage entry at a block’s state.

getStorageSize

Future<int?> getStorageSize(StorageKey key, {BlockHash? at})

Returns the size of a storage entry at a block’s state.

queryStorage

Future<List<StorageChangeSet>> queryStorage(List<StorageKey> keys, BlockHash fromBlock,{BlockHash? toBlock})

Query historical storage entries (by key) starting from a block given as the second parameter.

NOTE This first returned result contains the initial state of storage for all keys. Subsequent values in the vector represent changes to the previous state (diffs).

queryStorageAt

Future<List<StorageChangeSet>> queryStorageAt(List<StorageKey> keys, {BlockHash? at})

Query storage entries (by key) starting at block hash given as the second parameter.

getReadProof

Future<ReadProof> getReadProof(List<StorageKey> keys, {BlockHash? at})

Returns proof of storage entries at a specific block’s state.

getMetadata

Future<RuntimeMetadata> getMetadata({BlockHash? at})

Returns the runtime metadata

getRuntimeVersion

Future<RuntimeVersion> getRuntimeVersion({BlockHash? at})

Get the runtime version.

subscribeRuntimeVersion

Future<StreamSubscription<RuntimeVersion>> subscribeRuntimeVersion(Function(RuntimeVersion) onData)

Retrieves the runtime version via subscription

subscribeEvents

Future<StreamSubscription<Events>> subscribeEvents(BlockHash at, Function(Events) onData)

subscribeStorage

Future<StreamSubscription<StorageChangeSet>> subscribeStorage(List<Uint8List> storageKeys, Function(StorageChangeSet) onData)

Subscribes to storage changes for the provided keys

Example

import 'dart:typed_data';
import 'package:convert/convert.dart';
import 'package:polkadart/apis/apis.dart';
import 'package:polkadart/polkadart.dart' show Provider, StateApi;
void main() async {
final polkadart =
Provider.fromUri(Uri.parse('wss://rpc.matrix.canary.enjin.io'));
final state = StateApi(polkadart);
final runtimeVersion = await state.getRuntimeVersion();
print(runtimeVersion.toJson());
final author = AuthorApi(polkadart);
final extrinsic = hex.decode(
'350284004ea987928399dfe5b94bf7d37995850a21067bfa4549fa83b40250ee635fc06400036990f9642741b00d3484d2e5bd7cba6fa2eea682f6b6c612e47c204f09b0838c171ba42feae5bea1c48a48213cba42a5d590e1c07d1213d263a258f23f5102001c000a07004ea987928399dfe5b94bf7d37995850a21067bfa4549fa83b40250ee635fc064025a6202');
final submit = await author.submitAndWatchExtrinsic(extrinsic as Uint8List,
(data) => print('From here: ${data.type} - ${data.value}'));
print(submit);
await polkadot.disconnect();
}