Files
api/packages/rpc-core
Jaco Greeff c7c76f6edb Rework uniqTypes without duplication (#1316)
* Rework uniqTypes without  duplication

* Extra info for vX -> v7 conversion

* Add vX to naming

* Rework unwrap return

* Ignore gathering unique for v0

* Fix getUniq for V0 (well, def. throw-away, but anyway...)

* compareMap cleanup

* Cleanup author extraction

* Add modules via Struct.with (Metadata)

* Revert "Add modules via Struct.with (Metadata)"

This reverts commit 0666c3014cf840fb4ab26a5231cdf67dbe977bd7.

* Consistency in injected vs defined classes (Metadata)

* Add isTrue/isFalse to Bool

* Meta PlainType/MapType in registry

* Fix wrong v6 imports

* Extract storage modifier

* Split additional Metadata classes into interfaces

* Minor cleanups in type naming

* Static json renames

* Convert most V0 classes to interfaces

* Additional meta classes to interfaces

* No classes for Metadata V0 & V1 anymore

* Rename json imports

* Base cleanups

* Add polkadot static
2019-08-18 15:01:21 +02:00
..
2018-11-21 13:37:27 +01:00
2019-08-17 11:25:11 +00:00
2019-06-20 11:06:13 +02:00

@polkadot/rpc-core

This library provides a clean wrapper around all the methods exposed by a Polkadot network client.

Usage

Installation -

yarn add @polkadot/rpc-core

Initialisation -

import Rpc from '@polkadot/rpc-core';
import WsProvider from '@polkadot/rpc-provider/ws';

const provider = new WsProvider('http://127.0.0.1:9944');
const rpc = new Rpc(provider);

Retrieving the block header object for a given block header hash (a 0x-prefixed hex string with length of 64) -

rpc.chain
  .getHeader('0x1234567890')
  .subscribe(
    (header) => console.log(header),
    (error) => console.error('error:', error)
  );

Retrieving the best block number, parent hash, state root hash, extrinsics root hash, and digest (once-off) -

rpc.chain
  .getHead()
  .pipe(
    switchMap((headerHash) => {
      return rpc.chain.getHeader(headerHash);
    })
  )
  .subscribe(
    (header) => {
      console.log(`best #${header.blockNumber.toString()}`);
      console.log(`parentHash: ${header.parentHash.toString()}`);
      console.log(`stateRoot: ${header.stateRoot.toString()}`);
      console.log(`extrinsicsRoot: ${header.extrinsicsRoot.toString()}`);
      console.log(`digest: ${header.digest.toString()}`);
    },
    (error) => {
      console.error('error:', error);
    }
  );

Retrieving best header via subscription -

api.chain
rpc
  .subscribeNewHead()
  .subscribe(
    (header) => {
      console.log(`best #${header.blockNumber}`);
    },
    (error) => {
      console.error('error subscribing:', error);
    }
  );

Classes

Classes