Files
api/packages/rpc-core
Jaco GreeffandAmaury Martiny 022b938f00 Show section.method on storage read error (#928)
* Show section.method on storage read error

* Update packages/types/src/primitive/StorageKey.ts

Co-Authored-By: Amaury Martiny <amaury.martiny@protonmail.com>

* Update StorageKey.ts
2019-06-12 16:45:45 +12:00
..
2019-04-12 11:26:54 +12:00
2019-04-11 13:42:06 +12:00
2019-06-06 14:02:54 +12:00
2019-04-26 16:43:32 +12:00

@plugnet/rpc-core

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

Usage

Installation -

yarn add @plugnet/rpc-core

Initialisation -

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

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

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

api.chain
  .getHeader('0x1234567890')
  .then((header) => console.log(header))
  .catch((error) => console.error(error));

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

api.chain
  .getHead()
  .then((headerHash) => {
    return api.chain.getHeader(headerHash);
  })
  .then((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()}`);
  })
  .catch((error) => {
    console.error('error:', error);
  });

Retrieving best header via subscription -

api.chain
  .subscribeNewHead((header) => {
    console.log(`best #${header.blockNumber}`);
  })
  .then((subscriptionId) => {
    console.log(`subscriptionId: ${subscriptionId}`);
    // id for the subscription, can unsubscribe via
    // api.chain.subscribeNewHead.unsubscribe(subscriptionId);
  })
  .catch((error) => {
    console.error('error subscribing:', error);
  });

Classes

Classes