Skip to content

Polkadart API

We have two different ways to interact with the Polkadot or Polkadot based chains, through the Polkadart API and the network-specific APIs that are generated by the Polkadart CLI.

In this section, we will focus on the Polkadart API. If you are interested in the network-specific APIs, you can find them in the Blockchain API section.

Installation

The Polkadart API is available in the main package polkadart which provides tools to connect and interact with the Polkadot or Polkadot based chains. It abstracts the complexities of the network protocols and offers straightforward APIs.

Add the following to your pubspec.yaml file:

pubspec.yaml
dependencies:
polkadart: ^0.4.7

Get the dependencies by running:

Terminal window
dart pub get

Sample usage

demo.dart
import 'package:polkadart/apis/apis.dart';
import 'package:polkadart/polkadart.dart' show Provider, StateApi;
void main() async {
final provider = Provider.fromUri(Uri.parse('wss://rpc.polkadot.io'));
final stateApi = StateApi(polkadart);
final runtimeVersion = await stateApi.getRuntimeVersion();
print(runtimeVersion.toJson());
}

This will print the following output:

{
specName: polkadot,
implName: parity-polkadot,
authoringVersion: 0,
specVersion: 1003003,
implVersion: 0,
apis: [...],
transactionVersion: 26,
stateVersion: 1
}

The Polkadart APIs are static and do not change between different networks. They provide the most common functionalities that are shared across all networks.