@polkadot/api/rx (#233)
* api-rx (new) * Update SubmittableExtrinsic.ts * Update types.d.ts * Update index.ts * Retrieve genesisHash * extrinsics -> tx, state -> st * Update index.ts * Type cleanup * Update index.ts * Update index.ts * Update index.ts * Sign returns SubmittableExtrinsic * Example cleanup * Move to api-rx package * Add connected/disconnected events * Expand storage creation * isReady/isConnected * Add static create * Cleanup docs * Cleanups * ReplaySubjects * Basic tests * Add runtimeVersion * Test for version, meta & hash * Package location * Expand README * 2 ways of init * whenReady -> isReady * api-rx -> api/rx * Namings
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
[](https://polkadot.js.org)
|
||||

|
||||
[](https://github.com/Flet/semistandard)
|
||||
[](https://www.npmjs.com/package/@polkadot/api)
|
||||
[](https://travis-ci.org/polkadot-js/api)
|
||||
[](https://codeclimate.com/github/polkadot-js/api/maintainability)
|
||||
[](https://coveralls.io/github/polkadot-js/api?branch=master)
|
||||
[](https://david-dm.org/polkadot-js/api?path=packages/api)
|
||||
[](https://david-dm.org/polkadot-js/api?path=packages/api#info=devDependencies)
|
||||
|
||||
# @polkadot/api
|
||||
|
||||
An RxJs wrapper around [@polkadot/rpc-core](../rpc-core).
|
||||
|
||||
# Usage
|
||||
|
||||
Installation -
|
||||
|
||||
```
|
||||
npm install --save @polkadot/api/rx
|
||||
```
|
||||
|
||||
Making rpc calls -
|
||||
|
||||
```javascript
|
||||
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 -
|
||||
|
||||
```javascript
|
||||
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}`);
|
||||
});
|
||||
});
|
||||
```
|
||||
Reference in New Issue
Block a user