0.0.27 • Published 5 years ago

@chainx-v2/rpc-core v0.0.27

Weekly downloads
1
License
Apache-2.0
Repository
-
Last release
5 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

5 years ago

0.0.26

5 years ago

0.0.24

5 years ago

0.0.23

5 years ago

0.0.22

5 years ago

0.0.21

5 years ago

0.0.20

5 years ago

0.0.19

5 years ago

0.0.18

5 years ago

0.0.17

5 years ago

0.0.16

5 years ago

0.0.15

5 years ago

0.0.14

5 years ago

0.0.13

5 years ago

0.0.12

5 years ago

0.0.11

5 years ago

0.0.8

5 years ago

0.0.5

5 years ago

0.0.6

5 years ago

0.0.3-beta.26

5 years ago

0.0.4

5 years ago

0.0.3-beta.16

5 years ago

0.0.3-beta.18

5 years ago

0.0.3-beta.22

5 years ago

0.0.3-beta.24

5 years ago

0.0.3-beta.20

5 years ago

0.0.3-beta.21

5 years ago

0.0.3-beta.15

5 years ago

0.0.3-beta.11

5 years ago

0.0.3-beta.14

5 years ago

0.0.3-beta.10

5 years ago

0.0.3-beta.7

5 years ago

0.0.3-beta.6

5 years ago

0.0.3-beta.4

5 years ago

0.0.3-beta

5 years ago

0.0.2-beta

5 years ago

0.0.1-beta.16

5 years ago

0.0.1-beta.15

5 years ago

0.0.1-beta.14

5 years ago