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:
@@ -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`>
|
||||
|
||||
___
|
||||
|
||||
@@ -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` | `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` | `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` | `false` | `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` | `false` | `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` | `false` | `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` | `false` | `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`>
|
||||
|
||||
___
|
||||
|
||||
Reference in New Issue
Block a user