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