Files
api/docs/api
2018-10-11 07:38:36 +00:00
..
2018-10-11 07:38:36 +00:00
2018-10-11 07:38:36 +00:00
2018-10-11 07:38:36 +00:00
2018-10-11 07:38:36 +00:00
2018-10-10 18:23:34 +00:00
2018-10-10 18:23:34 +00:00

polkadotjs isc style npm travis maintainability coverage dependency devDependency

@polkadot/api

An RxJs wrapper around @polkadot/rpc-core.

Usage

Installation -

npm install --save @polkadot/api/rx

Making rpc calls -

import ApiRx from '@polkadot/api/rx';
// alternatively
// import { ApiRx } from '@polkadot/api';

// initialise via Promise & static create
const api = await ApiRx.create().toPromise();

// make a call to retrieve the current network head
api.rpc.chain.newHead().subscribe((header) => {
  console.log(`Chain is at #${header.blockNumber}`);
});

Subscribing to chain state -

import Api from '@polkadot/api';

// initialise via isReady & new
new Api().isReady.subscribe((api) => {
  // make a call to retrieve the current network head
  api.st.timestamp.now().subscribe((timestamp) => {
    console.log(`Current block timestamp ${timestamp}`);
  });
});