Add documentation and examples (#145)

* Add documentation

* Justification u8a decoding and json encoding (#146)

* Decode Justifications

* Json encoding for justifications

* Bump deps

* Allow extrinsic length encoding to operate on u8a[] (#148)

* Fix config and move generated doc to a subfolder

* Cleanup extrinsic encoding (#150)

* Cleanup extrinsic encoding

* Removed now-defunct type

* Add uncheckedLength encoding

* Add examples

* Ignore package-lock since we use yarn

* Cleanup examples

* Add gitbook config and some base files for the doc

* Do not make full doc mandatory for now

* Add contributing guide, polish doc and samples

* Update the deps of all samples and add yarn scripts
Fix and regenerate the doc

* Fix Contributing guide
This commit is contained in:
Chevdor
2018-09-15 09:11:56 +02:00
committed by Jaco Greeff
parent 7fffcb3747
commit 0981a30d84
61 changed files with 6937 additions and 105 deletions
+485
View File
@@ -0,0 +1,485 @@
[![polkadotjs](https://img.shields.io/badge/polkadot-js-orange.svg?style=flat-square)](https://polkadot.js.org) ![isc](https://img.shields.io/badge/license-ISC-lightgrey.svg?style=flat-square) [![style](https://img.shields.io/badge/code%20style-semistandard-lightgrey.svg?style=flat-square)](https://github.com/Flet/semistandard) [![npm](https://img.shields.io/npm/v/@polkadot/api-provider.svg?style=flat-square)](https://www.npmjs.com/package/@polkadot/api-provider) [![travis](https://img.shields.io/travis/polkadot-js/api.svg?style=flat-square)](https://travis-ci.org/polkadot-js/api) [![maintainability](https://img.shields.io/codeclimate/maintainability/polkadot-js/api.svg?style=flat-square)](https://codeclimate.com/github/polkadot-js/api/maintainability) [![coverage](https://img.shields.io/coveralls/polkadot-js/api.svg?style=flat-square)](https://coveralls.io/github/polkadot-js/api?branch=master) [![dependency](https://david-dm.org/polkadot-js/api.svg?style=flat-square&path=packages/api-provider)](https://david-dm.org/polkadot-js/api?path=packages/api-provider) [![devDependency](https://david-dm.org/polkadot-js/api/dev-status.svg?style=flat-square&path=packages/api-provider)](https://david-dm.org/polkadot-js/api?path=packages/api-provider#info=devDependencies)
@polkadot/api-provider
======================
Generic transport providers to handle the transport of method calls to and from Polkadot clients from applications interacting with it. Generally, unless you are operating at a low-level and taking care of encoding and decoding of parameters/results, it won't be directly used. API interfaces building on top these providers can support various transports with the same underlying interfaces.
Usage
-----
Installation -
```
npm install --save @polkadot/api-provider
```
Initialisation -
```js
import WsProvider from '@polkadot/api-provider/ws';
const provider = new WsProvider('http://127.0.0.1:9944');
const version = await provider.send('client_version', []);
console.log('clientVersion', version);
```
## Index
### Classes
* [HttpProvider](classes/httpprovider.md)
* [WsProvider](classes/wsprovider.md)
### Interfaces
* [ProviderInterface](interfaces/providerinterface.md)
### Type aliases
* [HttpState](#httpstate)
* [JsonRpcObject](#jsonrpcobject)
* [JsonRpcRequest](#jsonrpcrequest)
* [JsonRpcResponse](#jsonrpcresponse)
* [JsonRpcResponseBase](#jsonrpcresponsebase)
* [JsonRpcResponseBase$Error](#jsonrpcresponsebase_error)
* [MockState](#mockstate)
* [MockState$Requests](#mockstate_requests)
* [MockState$Storage](#mockstate_storage)
* [MockState$Subscription$Callback](#mockstate_subscription_callback)
* [MockState$Subscriptions](#mockstate_subscriptions)
* [ProviderInterface$Callback](#providerinterface_callback)
* [ProviderInterface$EmitCb](#providerinterface_emitcb)
* [ProviderInterface$Emitted](#providerinterface_emitted)
* [RpcCoder](#rpccoder)
* [RpcCoderState](#rpccoderstate)
### Functions
* [decodeResponse](#decoderesponse)
* [encodeJson](#encodejson)
* [encodeObject](#encodeobject)
* [mockProvider](#mockprovider)
* [mocks](#mocks)
* [on](#on)
* [rpcCoder](#rpccoder)
* [send](#send)
* [state](#state)
* [subscribe](#subscribe)
* [unsubscribe](#unsubscribe)
---
## Type aliases
<a id="httpstate"></a>
### HttpState
**Ƭ HttpState**: *`object`*
*Defined in [http/types.d.ts:8](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api-provider/src/http/types.d.ts#L8)*
#### Type declaration
___
<a id="jsonrpcobject"></a>
### JsonRpcObject
**Ƭ JsonRpcObject**: *`object`*
*Defined in [types.d.ts:5](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api-provider/src/types.d.ts#L5)*
#### Type declaration
___
<a id="jsonrpcrequest"></a>
### JsonRpcRequest
**Ƭ JsonRpcRequest**: * [JsonRpcObject](#jsonrpcobject) & `object`
*
*Defined in [types.d.ts:10](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api-provider/src/types.d.ts#L10)*
___
<a id="jsonrpcresponse"></a>
### JsonRpcResponse
**Ƭ JsonRpcResponse**: * [JsonRpcObject](#jsonrpcobject) & [JsonRpcResponseBase](#jsonrpcresponsebase)
*
*Defined in [types.d.ts:36](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api-provider/src/types.d.ts#L36)*
___
<a id="jsonrpcresponsebase"></a>
### JsonRpcResponseBase
**Ƭ JsonRpcResponseBase**: * `JsonRpcResponse$Single` & `JsonRpcResponse$Subscription`
*
*Defined in [types.d.ts:34](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api-provider/src/types.d.ts#L34)*
___
<a id="jsonrpcresponsebase_error"></a>
### JsonRpcResponseBase$Error
**Ƭ JsonRpcResponseBase$Error**: *`object`*
*Defined in [types.d.ts:15](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api-provider/src/types.d.ts#L15)*
#### Type declaration
___
<a id="mockstate"></a>
### MockState
**Ƭ MockState**: *`object`*
*Defined in [mock/types.d.ts:27](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api-provider/src/mock/types.d.ts#L27)*
#### Type declaration
___
<a id="mockstate_requests"></a>
### MockState$Requests
**Ƭ MockState$Requests**: *`object`*
*Defined in [mock/types.d.ts:23](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api-provider/src/mock/types.d.ts#L23)*
#### Type declaration
[index: `string`]: `function`
▸(storage: *[MockState$Storage](#mockstate_storage)*, params: *`Array`<`any`>*): `string`
**Parameters:**
| Param | Type |
| ------ | ------ |
| storage | [MockState$Storage](#mockstate_storage) |
| params | `Array`<`any`> |
**Returns:** `string`
___
<a id="mockstate_storage"></a>
### MockState$Storage
**Ƭ MockState$Storage**: *`object`*
*Defined in [mock/types.d.ts:19](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api-provider/src/mock/types.d.ts#L19)*
#### Type declaration
[index: `string`]: `Uint8Array`
___
<a id="mockstate_subscription_callback"></a>
### MockState$Subscription$Callback
**Ƭ MockState$Subscription$Callback**: *`function`*
*Defined in [mock/types.d.ts:8](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api-provider/src/mock/types.d.ts#L8)*
#### Type declaration
▸(error: * `Error` &#124; `null`*, value: *`any`*): `void`
**Parameters:**
| Param | Type |
| ------ | ------ |
| error | `Error` &#124; `null`|
| value | `any` |
**Returns:** `void`
___
<a id="mockstate_subscriptions"></a>
### MockState$Subscriptions
**Ƭ MockState$Subscriptions**: *`object`*
*Defined in [mock/types.d.ts:10](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api-provider/src/mock/types.d.ts#L10)*
#### Type declaration
[index: `string`]: `object`
___
<a id="providerinterface_callback"></a>
### ProviderInterface$Callback
**Ƭ ProviderInterface$Callback**: *`function`*
*Defined in [types.d.ts:38](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api-provider/src/types.d.ts#L38)*
#### Type declaration
▸(error: * `Error` &#124; `null`*, result: *`any`*): `void`
**Parameters:**
| Param | Type |
| ------ | ------ |
| error | `Error` &#124; `null`|
| result | `any` |
**Returns:** `void`
___
<a id="providerinterface_emitcb"></a>
### ProviderInterface$EmitCb
**Ƭ ProviderInterface$EmitCb**: *`function`*
*Defined in [types.d.ts:42](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api-provider/src/types.d.ts#L42)*
#### Type declaration
▸(value?: *`any`*): `any`
**Parameters:**
| Param | Type |
| ------ | ------ |
| `Optional` value | `any` |
**Returns:** `any`
___
<a id="providerinterface_emitted"></a>
### ProviderInterface$Emitted
**Ƭ ProviderInterface$Emitted**: * "connected" &#124; "disconnected"
*
*Defined in [types.d.ts:40](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api-provider/src/types.d.ts#L40)*
___
<a id="rpccoder"></a>
### RpcCoder
**Ƭ RpcCoder**: *`object`*
*Defined in [coder/json/types.d.ts:7](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api-provider/src/coder/json/types.d.ts#L7)*
#### Type declaration
___
<a id="rpccoderstate"></a>
### RpcCoderState
**Ƭ RpcCoderState**: *`object`*
*Defined in [coder/json/types.d.ts:14](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api-provider/src/coder/json/types.d.ts#L14)*
#### Type declaration
___
## Functions
<a id="decoderesponse"></a>
### decodeResponse
▸ **decodeResponse**(self: *[RpcCoderState](#rpccoderstate)*, response: *[JsonRpcResponse](#jsonrpcresponse)*): `any`
*Defined in [coder/json/decodeResponse.ts:22](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api-provider/src/coder/json/decodeResponse.ts#L22)*
**Parameters:**
| Param | Type |
| ------ | ------ |
| self | [RpcCoderState](#rpccoderstate) |
| response | [JsonRpcResponse](#jsonrpcresponse) |
**Returns:** `any`
___
<a id="encodejson"></a>
### encodeJson
▸ **encodeJson**(self: *[RpcCoderState](#rpccoderstate)*, method: *`string`*, params: *`Array`<`any`>*): `string`
*Defined in [coder/json/encodeJson.ts:9](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api-provider/src/coder/json/encodeJson.ts#L9)*
**Parameters:**
| Param | Type |
| ------ | ------ |
| self | [RpcCoderState](#rpccoderstate) |
| method | `string` |
| params | `Array`<`any`> |
**Returns:** `string`
___
<a id="encodeobject"></a>
### encodeObject
▸ **encodeObject**(self: *[RpcCoderState](#rpccoderstate)*, method: *`string`*, params: *`Array`<`any`>*): [JsonRpcRequest](#jsonrpcrequest)
*Defined in [coder/json/encodeObject.ts:8](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api-provider/src/coder/json/encodeObject.ts#L8)*
**Parameters:**
| Param | Type |
| ------ | ------ |
| self | [RpcCoderState](#rpccoderstate) |
| method | `string` |
| params | `Array`<`any`> |
**Returns:** [JsonRpcRequest](#jsonrpcrequest)
___
<a id="mockprovider"></a>
### mockProvider
▸ **mockProvider**(): [ProviderInterface](interfaces/providerinterface.md)
*Defined in [mock/index.ts:18](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api-provider/src/mock/index.ts#L18)*
A moock provider mainly used for testing.
**Returns:** [ProviderInterface](interfaces/providerinterface.md)
The mock provider
___
<a id="mocks"></a>
### mocks
▸ **mocks**(__namedParameters: *`object`*): `void`
*Defined in [mock/mocks.ts:68](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api-provider/src/mock/mocks.ts#L68)*
**Parameters:**
| Param | Type |
| ------ | ------ |
| __namedParameters | `object` |
**Returns:** `void`
___
<a id="on"></a>
### on
▸ **on**(self: *[MockState](#mockstate)*, type: *[ProviderInterface$Emitted](#providerinterface_emitted)*, sub: *[ProviderInterface$EmitCb](#providerinterface_emitcb)*): `void`
*Defined in [mock/on.ts:8](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api-provider/src/mock/on.ts#L8)*
**Parameters:**
| Param | Type |
| ------ | ------ |
| self | [MockState](#mockstate) |
| type | [ProviderInterface$Emitted](#providerinterface_emitted) |
| sub | [ProviderInterface$EmitCb](#providerinterface_emitcb) |
**Returns:** `void`
___
<a id="rpccoder"></a>
### rpcCoder
▸ **rpcCoder**(): [RpcCoder](#rpccoder)
*Defined in [coder/json/index.ts:12](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api-provider/src/coder/json/index.ts#L12)*
**Returns:** [RpcCoder](#rpccoder)
___
<a id="send"></a>
### send
▸ **send**(__namedParameters: *`object`*, method: *`string`*, params: *`Array`<`any`>*): `Promise`<`any`>
*Defined in [mock/send.ts:7](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api-provider/src/mock/send.ts#L7)*
**Parameters:**
| Param | Type |
| ------ | ------ |
| __namedParameters | `object` |
| method | `string` |
| params | `Array`<`any`> |
**Returns:** `Promise`<`any`>
___
<a id="state"></a>
### state
▸ **state**(): [MockState](#mockstate)
*Defined in [mock/state.ts:38](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api-provider/src/mock/state.ts#L38)*
**Returns:** [MockState](#mockstate)
___
<a id="subscribe"></a>
### subscribe
▸ **subscribe**(self: *[MockState](#mockstate)*, type: *`string`*, method: *`string`*, params: *`Array`<`any`>*): `Promise`<`number`>
*Defined in [mock/subscribe.ts:7](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api-provider/src/mock/subscribe.ts#L7)*
**Parameters:**
| Param | Type |
| ------ | ------ |
| self | [MockState](#mockstate) |
| type | `string` |
| method | `string` |
| params | `Array`<`any`> |
**Returns:** `Promise`<`number`>
___
<a id="unsubscribe"></a>
### unsubscribe
▸ **unsubscribe**(self: *[MockState](#mockstate)*, type: *`string`*, name: *`string`*, id: *`number`*): `Promise`<`boolean`>
*Defined in [mock/unsubscribe.ts:7](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api-provider/src/mock/unsubscribe.ts#L7)*
**Parameters:**
| Param | Type |
| ------ | ------ |
| self | [MockState](#mockstate) |
| type | `string` |
| name | `string` |
| id | `number` |
**Returns:** `Promise`<`boolean`>
___
+166
View File
@@ -0,0 +1,166 @@
[Polkadot JS API](../README.md) > [HttpProvider](../classes/httpprovider.md)
# Class: HttpProvider
The HTTP Provider allows sending requests using HTTP. it does not support subscriptions so you won´t be able to listen to events such as new blocks or balance changes. It is usually preferrable using the [WsProvider](wsprovider.md).
*__example__*: ```javascript
import createApi from '@polkadot/api';
import WsProvider from '@polkadot/api-provider/ws';
const provider = new WsProvider('http://127.0.0.1:9933');
const api = createApi(provider);
```
*__see__*: [WsProvider](wsprovider.md)
## Hierarchy
**HttpProvider**
## Implements
* [ProviderInterface](../interfaces/providerinterface.md)
## Index
### Constructors
* [constructor](httpprovider.md#constructor)
### Methods
* [isConnected](httpprovider.md#isconnected)
* [on](httpprovider.md#on)
* [send](httpprovider.md#send)
* [subscribe](httpprovider.md#subscribe)
* [unsubscribe](httpprovider.md#unsubscribe)
---
## Constructors
<a id="constructor"></a>
### constructor
⊕ **new HttpProvider**(endpoint: *`string`*): [HttpProvider](httpprovider.md)
*Defined in [http/index.ts:35](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api-provider/src/http/index.ts#L35)*
**Parameters:**
| Param | Type |
| ------ | ------ |
| endpoint | `string` |
**Returns:** [HttpProvider](httpprovider.md)
___
## Methods
<a id="isconnected"></a>
### isConnected
▸ **isConnected**(): `boolean`
*Implementation of [ProviderInterface](../interfaces/providerinterface.md).[isConnected](../interfaces/providerinterface.md#isconnected)*
*Defined in [http/index.ts:49](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api-provider/src/http/index.ts#L49)*
Whether the node is connected or not.
**Returns:** `boolean`
true if connected
___
<a id="on"></a>
### on
▸ **on**(type: *[ProviderInterface$Emitted](../#providerinterface_emitted)*, sub: *[ProviderInterface$EmitCb](../#providerinterface_emitcb)*): `void`
*Implementation of [ProviderInterface](../interfaces/providerinterface.md).[on](../interfaces/providerinterface.md#on)*
*Defined in [http/index.ts:56](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api-provider/src/http/index.ts#L56)*
Events are not supported with the HttpProvider, see [WsProvider](wsprovider.md).
**Parameters:**
| Param | Type |
| ------ | ------ |
| type | [ProviderInterface$Emitted](../#providerinterface_emitted) |
| sub | [ProviderInterface$EmitCb](../#providerinterface_emitcb) |
**Returns:** `void`
___
<a id="send"></a>
### send
▸ **send**(method: *`string`*, params: *`Array`<`any`>*): `Promise`<`any`>
*Implementation of [ProviderInterface](../interfaces/providerinterface.md).[send](../interfaces/providerinterface.md#send)*
*Defined in [http/index.ts:60](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api-provider/src/http/index.ts#L60)*
**Parameters:**
| Param | Type |
| ------ | ------ |
| method | `string` |
| params | `Array`<`any`> |
**Returns:** `Promise`<`any`>
___
<a id="subscribe"></a>
### subscribe
▸ **subscribe**(types: *`string`*, method: *`string`*, params: *`Array`<`any`>*, cb: *[ProviderInterface$Callback](../#providerinterface_callback)*): `Promise`<`number`>
*Implementation of [ProviderInterface](../interfaces/providerinterface.md).[subscribe](../interfaces/providerinterface.md#subscribe)*
*Defined in [http/index.ts:82](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api-provider/src/http/index.ts#L82)*
Subscriptions are not supported with the HttpProvider, see [WsProvider](wsprovider.md).
**Parameters:**
| Param | Type |
| ------ | ------ |
| types | `string` |
| method | `string` |
| params | `Array`<`any`> |
| cb | [ProviderInterface$Callback](../#providerinterface_callback) |
**Returns:** `Promise`<`number`>
___
<a id="unsubscribe"></a>
### unsubscribe
▸ **unsubscribe**(type: *`string`*, method: *`string`*, id: *`number`*): `Promise`<`boolean`>
*Implementation of [ProviderInterface](../interfaces/providerinterface.md).[unsubscribe](../interfaces/providerinterface.md#unsubscribe)*
*Defined in [http/index.ts:91](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api-provider/src/http/index.ts#L91)*
Subscriptions are not supported with the HttpProvider, see [WsProvider](wsprovider.md).
**Parameters:**
| Param | Type |
| ------ | ------ |
| type | `string` |
| method | `string` |
| id | `number` |
**Returns:** `Promise`<`boolean`>
___
+419
View File
@@ -0,0 +1,419 @@
[Polkadot JS API](../README.md) > [WsProvider](../classes/wsprovider.md)
# Class: WsProvider
The WebSocket Provider allows sending requests using WebSocket. Unlike the [HttpProvider](httpprovider.md), it does support subscriptions and allows listening to events such as new blocks or balance changes.
```javascript
import createApi from '@polkadot/api';
import WsProvider from '@polkadot/api-provider/ws';
const provider = new WsProvider('ws://127.0.0.1:9944');
const api = createApi(provider);
```
*__example__*: ```javascript
import createApi from '@polkadot/api';
import WsProvider from '@polkadot/api-provider/ws';
const provider = new WsProvider('ws://127.0.0.1:9944');
const api = createApi(provider);
```
*__see__*: [HttpProvider](httpprovider.md)
## Type parameters
#### EventTypes : `string` &#124; `symbol`
## Hierarchy
`EventEmitter`
**↳ WsProvider**
## Implements
* `WSProviderInterface`
## Index
### Modules
* [EventEmitter](../modules/wsprovider.eventemitter.md)
### Constructors
* [constructor](wsprovider.md#constructor)
### Properties
* [prefixed](wsprovider.md#prefixed)
### Methods
* [addListener](wsprovider.md#addlistener)
* [connect](wsprovider.md#connect)
* [emit](wsprovider.md#emit)
* [eventNames](wsprovider.md#eventnames)
* [isConnected](wsprovider.md#isconnected)
* [listenerCount](wsprovider.md#listenercount)
* [listeners](wsprovider.md#listeners)
* [off](wsprovider.md#off)
* [on](wsprovider.md#on)
* [once](wsprovider.md#once)
* [removeAllListeners](wsprovider.md#removealllisteners)
* [removeListener](wsprovider.md#removelistener)
* [send](wsprovider.md#send)
* [subscribe](wsprovider.md#subscribe)
* [unsubscribe](wsprovider.md#unsubscribe)
---
## Constructors
<a id="constructor"></a>
### constructor
⊕ **new WsProvider**(endpoint: *`string`*, autoConnect?: *`boolean`*): [WsProvider](wsprovider.md)
*Defined in [ws/index.ts:69](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api-provider/src/ws/index.ts#L69)*
**Parameters:**
| Param | Type | Default value | Description |
| ------ | ------ | ------ | ------ |
| endpoint | `string` | - | The endpoint url. Usually \`ws://ip:9944\` or \`wss://ip:9944\` |
| `Default value` autoConnect | `boolean` | true | Whether to connect automatically or not. |
**Returns:** [WsProvider](wsprovider.md)
___
## Properties
<a id="prefixed"></a>
### `<Static>` prefixed
**● prefixed**: * `string` &#124; `boolean`
*
*Inherited from EventEmitter.prefixed*
*Defined in /Users/will/projects/paritytech/polka/polkadot-js-api/node_modules/eventemitter3/index.d.ts:6*
___
## Methods
<a id="addlistener"></a>
### addListener
▸ **addListener**(event: *`EventTypes`*, fn: *`ListenerFn`*, context?: *`any`*): `this`
*Inherited from EventEmitter.addListener*
*Defined in /Users/will/projects/paritytech/polka/polkadot-js-api/node_modules/eventemitter3/index.d.ts:33*
**Parameters:**
| Param | Type |
| ------ | ------ |
| event | `EventTypes` |
| fn | `ListenerFn` |
| `Optional` context | `any` |
**Returns:** `this`
___
<a id="connect"></a>
### connect
▸ **connect**(): `void`
*Defined in [ws/index.ts:99](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api-provider/src/ws/index.ts#L99)*
The [WsProvider](wsprovider.md) connects automatically by default. if you decided otherwise, you may connect manually using this method.
**Returns:** `void`
___
<a id="emit"></a>
### emit
▸ **emit**(event: *`EventTypes`*, ...args: *`Array`<`any`>*): `boolean`
*Inherited from EventEmitter.emit*
*Defined in /Users/will/projects/paritytech/polka/polkadot-js-api/node_modules/eventemitter3/index.d.ts:27*
Calls each of the listeners registered for a given event.
**Parameters:**
| Param | Type |
| ------ | ------ |
| event | `EventTypes` |
| `Rest` args | `Array`<`any`> |
**Returns:** `boolean`
___
<a id="eventnames"></a>
### eventNames
▸ **eventNames**(): `Array`<`EventTypes`>
*Inherited from EventEmitter.eventNames*
*Defined in /Users/will/projects/paritytech/polka/polkadot-js-api/node_modules/eventemitter3/index.d.ts:12*
Return an array listing the events for which the emitter has registered listeners.
**Returns:** `Array`<`EventTypes`>
___
<a id="isconnected"></a>
### isConnected
▸ **isConnected**(): `boolean`
*Defined in [ws/index.ts:116](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api-provider/src/ws/index.ts#L116)*
Whether the node is connected or not.
**Returns:** `boolean`
true if connected
___
<a id="listenercount"></a>
### listenerCount
▸ **listenerCount**(event: *`EventTypes`*): `number`
*Inherited from EventEmitter.listenerCount*
*Defined in /Users/will/projects/paritytech/polka/polkadot-js-api/node_modules/eventemitter3/index.d.ts:22*
Return the number of listeners listening to a given event.
**Parameters:**
| Param | Type |
| ------ | ------ |
| event | `EventTypes` |
**Returns:** `number`
___
<a id="listeners"></a>
### listeners
▸ **listeners**(event: *`EventTypes`*): `Array`<`ListenerFn`>
*Inherited from EventEmitter.listeners*
*Defined in /Users/will/projects/paritytech/polka/polkadot-js-api/node_modules/eventemitter3/index.d.ts:17*
Return the listeners registered for a given event.
**Parameters:**
| Param | Type |
| ------ | ------ |
| event | `EventTypes` |
**Returns:** `Array`<`ListenerFn`>
___
<a id="off"></a>
### off
▸ **off**(event: *`EventTypes`*, fn?: *[ListenerFn](../interfaces/wsprovider.eventemitter.listenerfn.md)*, context?: *`any`*, once?: * `undefined` &#124; `false` &#124; `true`*): `this`
*Inherited from EventEmitter.off*
*Defined in /Users/will/projects/paritytech/polka/polkadot-js-api/node_modules/eventemitter3/index.d.ts:44*
**Parameters:**
| Param | Type |
| ------ | ------ |
| event | `EventTypes` |
| `Optional` fn | [ListenerFn](../interfaces/wsprovider.eventemitter.listenerfn.md) |
| `Optional` context | `any` |
| `Optional` once | `undefined` &#124; `false` &#124; `true`|
**Returns:** `this`
___
<a id="on"></a>
### on
▸ **on**(type: *[ProviderInterface$Emitted](../#providerinterface_emitted)*, sub: *[ProviderInterface$EmitCb](../#providerinterface_emitcb)*): `this`
*Overrides EventEmitter.on*
*Defined in [ws/index.ts:126](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api-provider/src/ws/index.ts#L126)*
Listens on events after having subscribed using the [subscribe](wsprovider.md#subscribe) function.
**Parameters:**
| Param | Type | Description |
| ------ | ------ | ------ |
| type | [ProviderInterface$Emitted](../#providerinterface_emitted) | Event |
| sub | [ProviderInterface$EmitCb](../#providerinterface_emitcb) | Callback |
**Returns:** `this`
[description]
___
<a id="once"></a>
### once
▸ **once**(event: *`EventTypes`*, fn: *`ListenerFn`*, context?: *`any`*): `this`
*Inherited from EventEmitter.once*
*Defined in /Users/will/projects/paritytech/polka/polkadot-js-api/node_modules/eventemitter3/index.d.ts:38*
Add a one-time listener for a given event.
**Parameters:**
| Param | Type |
| ------ | ------ |
| event | `EventTypes` |
| fn | `ListenerFn` |
| `Optional` context | `any` |
**Returns:** `this`
___
<a id="removealllisteners"></a>
### removeAllListeners
▸ **removeAllListeners**(event?: *[EventTypes]()*): `this`
*Inherited from EventEmitter.removeAllListeners*
*Defined in /Users/will/projects/paritytech/polka/polkadot-js-api/node_modules/eventemitter3/index.d.ts:49*
Remove all listeners, or those of the specified event.
**Parameters:**
| Param | Type |
| ------ | ------ |
| `Optional` event | [EventTypes]() |
**Returns:** `this`
___
<a id="removelistener"></a>
### removeListener
▸ **removeListener**(event: *`EventTypes`*, fn?: *[ListenerFn](../interfaces/wsprovider.eventemitter.listenerfn.md)*, context?: *`any`*, once?: * `undefined` &#124; `false` &#124; `true`*): `this`
*Inherited from EventEmitter.removeListener*
*Defined in /Users/will/projects/paritytech/polka/polkadot-js-api/node_modules/eventemitter3/index.d.ts:43*
Remove the listeners of a given event.
**Parameters:**
| Param | Type |
| ------ | ------ |
| event | `EventTypes` |
| `Optional` fn | [ListenerFn](../interfaces/wsprovider.eventemitter.listenerfn.md) |
| `Optional` context | `any` |
| `Optional` once | `undefined` &#124; `false` &#124; `true`|
**Returns:** `this`
___
<a id="send"></a>
### send
▸ **send**(method: *`string`*, params: *`Array`<`any`>*, subscription?: *`SubscriptionHandler`*): `Promise`<`any`>
*Defined in [ws/index.ts:130](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api-provider/src/ws/index.ts#L130)*
**Parameters:**
| Param | Type |
| ------ | ------ |
| method | `string` |
| params | `Array`<`any`> |
| `Optional` subscription | `SubscriptionHandler` |
**Returns:** `Promise`<`any`>
___
<a id="subscribe"></a>
### subscribe
▸ **subscribe**(type: *`string`*, method: *`string`*, params: *`Array`<`any`>*, callback: *[ProviderInterface$Callback](../#providerinterface_callback)*): `Promise`<`number`>
*Defined in [ws/index.ts:182](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api-provider/src/ws/index.ts#L182)*
Allows subscribing to a specific event.
*__example__*: ```javascript
const provider = new WsProvider('ws://127.0.0.1:9944')
const api = createApi(provider)
api.state.storage([[storage.staking.public.freeBalanceOf, <Address>]], (_, values) => {
console.log(values)
}).then((subscriptionId) => {
console.log('balance changes subscription id: ', subscriptionId)
})
```
**Parameters:**
| Param | Type | Description |
| ------ | ------ | ------ |
| type | `string` | Subscription type |
| method | `string` | Subscription method |
| params | `Array`<`any`> | Parameters |
| callback | [ProviderInterface$Callback](../#providerinterface_callback) | Callback |
**Returns:** `Promise`<`number`>
Promise resolving to the dd of the subscription you can use with [[unsubscribe]]
___
<a id="unsubscribe"></a>
### unsubscribe
▸ **unsubscribe**(type: *`string`*, method: *`string`*, id: *`number`*): `Promise`<`boolean`>
*Defined in [ws/index.ts:191](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api-provider/src/ws/index.ts#L191)*
Allows unsubscribing to subscriptions made with [subscribe](wsprovider.md#subscribe).
**Parameters:**
| Param | Type |
| ------ | ------ |
| type | `string` |
| method | `string` |
| id | `number` |
**Returns:** `Promise`<`boolean`>
___
@@ -0,0 +1,113 @@
[Polkadot JS API](../README.md) > [ProviderInterface](../interfaces/providerinterface.md)
# Interface: ProviderInterface
## Hierarchy
**ProviderInterface**
## Implemented by
* [HttpProvider](../classes/httpprovider.md)
## Index
### Methods
* [isConnected](providerinterface.md#isconnected)
* [on](providerinterface.md#on)
* [send](providerinterface.md#send)
* [subscribe](providerinterface.md#subscribe)
* [unsubscribe](providerinterface.md#unsubscribe)
---
## Methods
<a id="isconnected"></a>
### isConnected
▸ **isConnected**(): `boolean`
*Defined in [types.d.ts:45](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api-provider/src/types.d.ts#L45)*
**Returns:** `boolean`
___
<a id="on"></a>
### on
▸ **on**(type: *[ProviderInterface$Emitted](../#providerinterface_emitted)*, sub: *[ProviderInterface$EmitCb](../#providerinterface_emitcb)*): `void`
*Defined in [types.d.ts:46](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api-provider/src/types.d.ts#L46)*
**Parameters:**
| Param | Type |
| ------ | ------ |
| type | [ProviderInterface$Emitted](../#providerinterface_emitted) |
| sub | [ProviderInterface$EmitCb](../#providerinterface_emitcb) |
**Returns:** `void`
___
<a id="send"></a>
### send
▸ **send**(method: *`string`*, params: *`Array`<`any`>*): `Promise`<`any`>
*Defined in [types.d.ts:47](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api-provider/src/types.d.ts#L47)*
**Parameters:**
| Param | Type |
| ------ | ------ |
| method | `string` |
| params | `Array`<`any`> |
**Returns:** `Promise`<`any`>
___
<a id="subscribe"></a>
### subscribe
▸ **subscribe**(type: *`string`*, method: *`string`*, params: *`Array`<`any`>*, cb: *[ProviderInterface$Callback](../#providerinterface_callback)*): `Promise`<`number`>
*Defined in [types.d.ts:48](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api-provider/src/types.d.ts#L48)*
**Parameters:**
| Param | Type |
| ------ | ------ |
| type | `string` |
| method | `string` |
| params | `Array`<`any`> |
| cb | [ProviderInterface$Callback](../#providerinterface_callback) |
**Returns:** `Promise`<`number`>
___
<a id="unsubscribe"></a>
### unsubscribe
▸ **unsubscribe**(type: *`string`*, method: *`string`*, id: *`number`*): `Promise`<`boolean`>
*Defined in [types.d.ts:49](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api-provider/src/types.d.ts#L49)*
**Parameters:**
| Param | Type |
| ------ | ------ |
| type | `string` |
| method | `string` |
| id | `number` |
**Returns:** `Promise`<`boolean`>
___
@@ -0,0 +1,34 @@
[Polkadot JS API](../README.md) > [WsProvider](../classes/wsprovider.md) > [EventEmitter](../modules/wsprovider.eventemitter.md) > [EventEmitterStatic](../interfaces/wsprovider.eventemitter.eventemitterstatic.md)
# Interface: EventEmitterStatic
## Hierarchy
**EventEmitterStatic**
## Index
### Constructors
* [constructor](wsprovider.eventemitter.eventemitterstatic.md#constructor)
---
## Constructors
<a id="constructor"></a>
### constructor
⊕ **new EventEmitterStatic**<`EventTypes`>(): `EventEmitter`<`EventTypes`>
*Defined in /Users/will/projects/paritytech/polka/polkadot-js-api/node_modules/eventemitter3/index.d.ts:57*
**Type parameters:**
#### EventTypes : `string` &#124; `symbol`
**Returns:** `EventEmitter`<`EventTypes`>
___
@@ -0,0 +1,25 @@
[Polkadot JS API](../README.md) > [WsProvider](../classes/wsprovider.md) > [EventEmitter](../modules/wsprovider.eventemitter.md) > [ListenerFn](../interfaces/wsprovider.eventemitter.listenerfn.md)
# Interface: ListenerFn
## Hierarchy
**ListenerFn**
## Callable
▸ **__call**(...args: *`Array`<`any`>*): `void`
*Defined in /Users/will/projects/paritytech/polka/polkadot-js-api/node_modules/eventemitter3/index.d.ts:53*
**Parameters:**
| Param | Type |
| ------ | ------ |
| `Rest` args | `Array`<`any`> |
**Returns:** `void`
## Index
---
@@ -0,0 +1,29 @@
[Polkadot JS API](../README.md) > [WsProvider](../classes/wsprovider.md) > [EventEmitter](../modules/wsprovider.eventemitter.md)
# Module: EventEmitter
## Index
### Interfaces
* [EventEmitterStatic](../interfaces/wsprovider.eventemitter.eventemitterstatic.md)
* [ListenerFn](../interfaces/wsprovider.eventemitter.listenerfn.md)
### Variables
* [EventEmitter](wsprovider.eventemitter.md#eventemitter)
---
## Variables
<a id="eventemitter"></a>
### `<Const>` EventEmitter
**● EventEmitter**: *`EventEmitterStatic`*
*Defined in /Users/will/projects/paritytech/polka/polkadot-js-api/node_modules/eventemitter3/index.d.ts:61*
___