0.0.27 • Published 4 years ago

@chainx-v2/rpc-core v0.0.27

Weekly downloads
1
License
Apache-2.0
Repository
-
Last release
4 years ago

@chainx-v2/rpc-core

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

Usage

Installation -

yarn add @chainx-v2/rpc-core

Initialisation -

import Rpc from '@chainx-v2/rpc-core';
import WsProvider from '@chainx-v2/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.number.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
  .subscribeNewHeads()
  .subscribe(
    (header) => {
      console.log(`best #${header.number}`);
    },
    (error) => {
      console.error('error subscribing:', error);
    }
  );

Classes

Classes

0.0.27

4 years ago

0.0.26

4 years ago

0.0.24

4 years ago

0.0.23

4 years ago

0.0.22

4 years ago

0.0.21

4 years ago

0.0.20

4 years ago

0.0.19

4 years ago

0.0.18

4 years ago

0.0.17

4 years ago

0.0.16

4 years ago

0.0.15

4 years ago

0.0.14

4 years ago

0.0.13

4 years ago

0.0.12

4 years ago

0.0.11

4 years ago

0.0.8

4 years ago

0.0.5

4 years ago

0.0.6

4 years ago

0.0.3-beta.26

4 years ago

0.0.4

4 years ago

0.0.3-beta.16

4 years ago

0.0.3-beta.18

4 years ago

0.0.3-beta.22

4 years ago

0.0.3-beta.24

4 years ago

0.0.3-beta.20

4 years ago

0.0.3-beta.21

4 years ago

0.0.3-beta.15

4 years ago

0.0.3-beta.11

4 years ago

0.0.3-beta.14

4 years ago

0.0.3-beta.10

4 years ago

0.0.3-beta.7

4 years ago

0.0.3-beta.6

4 years ago

0.0.3-beta.4

4 years ago

0.0.3-beta

4 years ago

0.0.2-beta

4 years ago

0.0.1-beta.16

4 years ago

0.0.1-beta.15

4 years ago

0.0.1-beta.14

4 years ago