JSPM

@polkadot/api

0.31.4
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 145524
  • Score
    100M100P100Q155681F
  • License ISC

An RxJS wrapper around the Polkadot JS RPC

Package Exports

  • @polkadot/api
  • @polkadot/api/index
  • @polkadot/api/rx

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@polkadot/api) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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}`);
  });
});