[CI Skip] 0.31.13
This commit is contained in:
@@ -2,7 +2,14 @@
|
||||
@polkadot/rpc-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.
|
||||
Generic transport providers to handle the transport of method calls to and from Polkadot clients from applications interacting with it. It provides an interface to making RPC class and is 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, rather only passed to a higher-level interface.
|
||||
|
||||
Provider Selection
|
||||
------------------
|
||||
|
||||
There are two flavours of the providers provided, one allowing for using HTTP as a transport machanism, the other using WebSockets. It is generally recommended to use the [WsProvider](classes/_ws_index_.wsprovider.md) since in addition to standard calls, it allows for subscriptions where all changes to state can be pushed from the node to the client.
|
||||
|
||||
Both providers are usable (as is the API), in both browser-based and Node.js environments. Polyfills for unsupported functionality are automatically applied based on feature-detection.
|
||||
|
||||
Usage
|
||||
-----
|
||||
@@ -13,14 +20,27 @@ Installation -
|
||||
yarn add @polkadot/rpc-provider
|
||||
```
|
||||
|
||||
Initialisation -
|
||||
WebSocket Initialisation -
|
||||
|
||||
```js
|
||||
```javascript
|
||||
import WsProvider from '@polkadot/rpc-provider/ws';
|
||||
|
||||
const provider = new WsProvider('http://127.0.0.1:9944');
|
||||
// this is the actual default endpoint
|
||||
const provider = new WsProvider('ws://127.0.0.1:9944');
|
||||
const version = await provider.send('client_version', []);
|
||||
|
||||
console.log('clientVersion', version);
|
||||
console.log('client version', version);
|
||||
```
|
||||
|
||||
HTTP Initialisation -
|
||||
|
||||
```javascript
|
||||
import { HttpProvider } from '@polkadot/rpc-provider';
|
||||
|
||||
// this is the actual default endpoint
|
||||
const provider = new HttpProvider('http://127.0.0.1:9933');
|
||||
const version = await provider.send('chain_getBlockHash', []);
|
||||
|
||||
console.log('latest block Hash', hash);
|
||||
```
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
* ["coder/json/encodeJson"](modules/_coder_json_encodejson_.md)
|
||||
* ["coder/json/encodeObject"](modules/_coder_json_encodeobject_.md)
|
||||
* ["coder/json/index"](modules/_coder_json_index_.md)
|
||||
* ["defaults"](modules/_defaults_.md)
|
||||
* ["http/index"](modules/_http_index_.md)
|
||||
* [HttpProvider](classes/_http_index_.httpprovider.md)
|
||||
* ["http/polyfill"](modules/_http_polyfill_.md)
|
||||
|
||||
@@ -195,70 +195,6 @@
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4" data-path="../../rpc-core/">
|
||||
|
||||
<a href="../../rpc-core/">
|
||||
|
||||
|
||||
rpc-core
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
<ul class="articles">
|
||||
|
||||
|
||||
<li class="chapter " data-level="1.4.1" data-path="../../rpc-core/classes/_index_.rpc.html">
|
||||
|
||||
<a href="../../rpc-core/classes/_index_.rpc.html">
|
||||
|
||||
|
||||
Rpc
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.5" data-path="../../rpc-rx/">
|
||||
|
||||
<a href="../../rpc-rx/">
|
||||
|
||||
|
||||
rpc-rx
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
<ul class="articles">
|
||||
|
||||
|
||||
<li class="chapter " data-level="1.5.1" data-path="../../rpc-rx/classes/_index_.rpcrx.html">
|
||||
|
||||
<a href="../../rpc-rx/classes/_index_.rpcrx.html">
|
||||
|
||||
|
||||
RpcRx
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
@@ -428,15 +364,16 @@
|
||||
|
||||
<section class="normal markdown-section">
|
||||
|
||||
<p><em><strong>name</strong></em>: HttpProvider</p>
|
||||
<h1 id="polkadotrpc-providerhttps">@polkadot/rpc-provider/https</h1>
|
||||
<p><em><strong>name</strong></em>: HttpProvider</p>
|
||||
<p><em><strong>summary</strong></em>: The HTTP Provider allows sending requests using HTTP to a HTTP RPC server TCP port.</p>
|
||||
<p><em><strong>description</strong></em>: 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 <a href="_ws_index_.wsprovider.html">WsProvider</a>.</p>
|
||||
<p><em><strong>example</strong></em>: </p>
|
||||
<pre><code class="lang-javascript"><div class="sunlight-container sunlight-theme-gitbook"><div class="sunlight-code-container"><pre class="sunlight-highlight-javascript sunlight-highlighted"><span class="sunlight-javascript"><span class="sunlight-reservedWord">import</span> <span class="sunlight-ident">Rpc</span> <span class="sunlight-ident">from</span> <span class="sunlight-string">'@polkadot/rpc-core'</span><span class="sunlight-punctuation">;</span>
|
||||
<pre><code class="lang-javascript"><div class="sunlight-container sunlight-theme-gitbook"><div class="sunlight-code-container"><pre class="sunlight-highlight-javascript sunlight-highlighted"><span class="sunlight-javascript"><span class="sunlight-reservedWord">import</span> <span class="sunlight-ident">Api</span> <span class="sunlight-ident">from</span> <span class="sunlight-string">'@polkadot/api/promise'</span><span class="sunlight-punctuation">;</span>
|
||||
<span class="sunlight-reservedWord">import</span> <span class="sunlight-ident">HttpProvider</span> <span class="sunlight-ident">from</span> <span class="sunlight-string">'@polkadot/rpc-provider/http'</span><span class="sunlight-punctuation">;</span>
|
||||
|
||||
<span class="sunlight-reservedWord">const</span> <span class="sunlight-ident">provider</span> <span class="sunlight-operator">=</span> <span class="sunlight-keyword">new</span> <span class="sunlight-ident">HttpProvider</span><span class="sunlight-punctuation">(</span><span class="sunlight-string">'http://127.0.0.1:9933'</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
|
||||
<span class="sunlight-reservedWord">const</span> <span class="sunlight-ident">api</span> <span class="sunlight-operator">=</span> <span class="sunlight-keyword">new</span> <span class="sunlight-ident">Rpc</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">provider</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
|
||||
<span class="sunlight-reservedWord">const</span> <span class="sunlight-ident">api</span> <span class="sunlight-operator">=</span> <span class="sunlight-keyword">new</span> <span class="sunlight-ident">Api</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">provider</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
|
||||
</span></pre></div></div></code></pre>
|
||||
<p><em><strong>see</strong></em>: <a href="_ws_index_.wsprovider.html">WsProvider</a></p>
|
||||
<h1 id="hierarchy">Hierarchy</h1>
|
||||
@@ -448,21 +385,23 @@
|
||||
<h1 id="constructors">Constructors</h1>
|
||||
<p><a id="constructor"></a></p>
|
||||
<h2 id="constructor">constructor</h2>
|
||||
<p>⊕ <strong>new HttpProvider</strong>(endpoint: <em><code>string</code></em>): <a href="_http_index_.httpprovider.html">HttpProvider</a></p>
|
||||
<p><em>Defined in <a href="https://github.com/polkadot-js/api/blob/e103e98/packages/rpc-provider/src/http/index.ts#L40" target="_blank">http/index.ts:40</a></em></p>
|
||||
<p>⊕ <strong>new HttpProvider</strong>(endpoint?: <em><code>string</code></em>): <a href="_http_index_.httpprovider.html">HttpProvider</a></p>
|
||||
<p><em>Defined in <a href="https://github.com/polkadot-js/api/blob/2b88a8f/packages/rpc-provider/src/http/index.ts#L43" target="_blank">http/index.ts:43</a></em></p>
|
||||
<p><strong>Parameters:</strong></p>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Param</th>
|
||||
<th>Type</th>
|
||||
<th>Default value</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>endpoint</td>
|
||||
<td><code>Default value</code> endpoint</td>
|
||||
<td><code>string</code></td>
|
||||
<td>defaults.HTTP_URL</td>
|
||||
<td>The endpoint url starting with http://</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
@@ -473,7 +412,7 @@
|
||||
<p><a id="isconnected"></a></p>
|
||||
<h2 id="isconnected">isConnected</h2>
|
||||
<p>▸ <strong>isConnected</strong>(): <code>boolean</code></p>
|
||||
<p><em>Defined in <a href="https://github.com/polkadot-js/api/blob/e103e98/packages/rpc-provider/src/http/index.ts#L57" target="_blank">http/index.ts:57</a></em></p>
|
||||
<p><em>Defined in <a href="https://github.com/polkadot-js/api/blob/2b88a8f/packages/rpc-provider/src/http/index.ts#L60" target="_blank">http/index.ts:60</a></em></p>
|
||||
<p><em><strong>summary</strong></em>: Whether the node is connected or not.</p>
|
||||
<p><strong>Returns:</strong> <code>boolean</code>
|
||||
true if connected</p>
|
||||
@@ -481,7 +420,7 @@ true if connected</p>
|
||||
<p><a id="on"></a></p>
|
||||
<h2 id="on">on</h2>
|
||||
<p>▸ <strong>on</strong>(type: <em><code>ProviderInterface$Emitted</code></em>, sub: <em><code>ProviderInterface$EmitCb</code></em>): <code>void</code></p>
|
||||
<p><em>Defined in <a href="https://github.com/polkadot-js/api/blob/e103e98/packages/rpc-provider/src/http/index.ts#L65" target="_blank">http/index.ts:65</a></em></p>
|
||||
<p><em>Defined in <a href="https://github.com/polkadot-js/api/blob/2b88a8f/packages/rpc-provider/src/http/index.ts#L68" target="_blank">http/index.ts:68</a></em></p>
|
||||
<p><em><strong>summary</strong></em>: Events are not supported with the HttpProvider, see <a href="_ws_index_.wsprovider.html">WsProvider</a>.</p>
|
||||
<p><em><strong>description</strong></em>: HTTP Provider does not have 'on' emitters. WebSockets should be used instead.</p>
|
||||
<p><strong>Parameters:</strong></p>
|
||||
@@ -508,7 +447,7 @@ true if connected</p>
|
||||
<p><a id="send"></a></p>
|
||||
<h2 id="send">send</h2>
|
||||
<p>▸ <strong>send</strong>(method: <em><code>string</code></em>, params: <em><code>Array</code><<code>any</code>></em>): <code>Promise</code><<code>any</code>></p>
|
||||
<p><em>Defined in <a href="https://github.com/polkadot-js/api/blob/e103e98/packages/rpc-provider/src/http/index.ts#L72" target="_blank">http/index.ts:72</a></em></p>
|
||||
<p><em>Defined in <a href="https://github.com/polkadot-js/api/blob/2b88a8f/packages/rpc-provider/src/http/index.ts#L75" target="_blank">http/index.ts:75</a></em></p>
|
||||
<p><em><strong>summary</strong></em>: Send HTTP POST Request with Body to configured HTTP Endpoint.</p>
|
||||
<p><strong>Parameters:</strong></p>
|
||||
<table>
|
||||
@@ -534,7 +473,7 @@ true if connected</p>
|
||||
<p><a id="subscribe"></a></p>
|
||||
<h2 id="subscribe">subscribe</h2>
|
||||
<p>▸ <strong>subscribe</strong>(types: <em><code>string</code></em>, method: <em><code>string</code></em>, params: <em><code>Array</code><<code>any</code>></em>, cb: <em><code>ProviderInterface$Callback</code></em>): <code>Promise</code><<code>number</code>></p>
|
||||
<p><em>Defined in <a href="https://github.com/polkadot-js/api/blob/e103e98/packages/rpc-provider/src/http/index.ts#L94" target="_blank">http/index.ts:94</a></em></p>
|
||||
<p><em>Defined in <a href="https://github.com/polkadot-js/api/blob/2b88a8f/packages/rpc-provider/src/http/index.ts#L97" target="_blank">http/index.ts:97</a></em></p>
|
||||
<p><em><strong>summary</strong></em>: Subscriptions are not supported with the HttpProvider, see <a href="_ws_index_.wsprovider.html">WsProvider</a>.</p>
|
||||
<p><strong>Parameters:</strong></p>
|
||||
<table>
|
||||
@@ -568,7 +507,7 @@ true if connected</p>
|
||||
<p><a id="unsubscribe"></a></p>
|
||||
<h2 id="unsubscribe">unsubscribe</h2>
|
||||
<p>▸ <strong>unsubscribe</strong>(type: <em><code>string</code></em>, method: <em><code>string</code></em>, id: <em><code>number</code></em>): <code>Promise</code><<code>boolean</code>></p>
|
||||
<p><em>Defined in <a href="https://github.com/polkadot-js/api/blob/e103e98/packages/rpc-provider/src/http/index.ts#L103" target="_blank">http/index.ts:103</a></em></p>
|
||||
<p><em>Defined in <a href="https://github.com/polkadot-js/api/blob/2b88a8f/packages/rpc-provider/src/http/index.ts#L106" target="_blank">http/index.ts:106</a></em></p>
|
||||
<p><em><strong>summary</strong></em>: Subscriptions are not supported with the HttpProvider, see <a href="_ws_index_.wsprovider.html">WsProvider</a>.</p>
|
||||
<p><strong>Parameters:</strong></p>
|
||||
<table>
|
||||
@@ -638,7 +577,7 @@ true if connected</p>
|
||||
<script>
|
||||
var gitbook = gitbook || [];
|
||||
gitbook.push(function() {
|
||||
gitbook.page.hasChanged({"page":{"title":"HttpProvider","level":"1.3.1","depth":2,"next":{"title":"WsProvider","level":"1.3.2","depth":2,"path":"rpc-provider/classes/_ws_index_.wsprovider.md","ref":"rpc-provider/classes/_ws_index_.wsprovider.md","articles":[]},"previous":{"title":"rpc-provider","level":"1.3","depth":1,"path":"rpc-provider/README.md","ref":"rpc-provider/README.md","articles":[{"title":"HttpProvider","level":"1.3.1","depth":2,"path":"rpc-provider/classes/_http_index_.httpprovider.md","ref":"rpc-provider/classes/_http_index_.httpprovider.md","articles":[]},{"title":"WsProvider","level":"1.3.2","depth":2,"path":"rpc-provider/classes/_ws_index_.wsprovider.md","ref":"rpc-provider/classes/_ws_index_.wsprovider.md","articles":[]}]},"dir":"ltr"},"config":{"plugins":["include-codeblock","mermaid-gb3","-highlight","sunlight-highlighter"],"root":"docs","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"sunlight-highlighter":{"theme":"gitbook","lineNumbers":false},"include-codeblock":{"check":false,"edit":false,"lang":"","fixlang":false,"template":"default","theme":"chrome","unindent":false},"mermaid-gb3":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Polkadot API Book","gitbook":">=2.4.0"},"file":{"path":"rpc-provider/classes/_http_index_.httpprovider.md","mtime":"2018-10-11T16:51:08.021Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-10-11T16:52:14.838Z"},"basePath":"../..","book":{"language":""}});
|
||||
gitbook.page.hasChanged({"page":{"title":"HttpProvider","level":"1.3.1","depth":2,"next":{"title":"WsProvider","level":"1.3.2","depth":2,"path":"rpc-provider/classes/_ws_index_.wsprovider.md","ref":"rpc-provider/classes/_ws_index_.wsprovider.md","articles":[]},"previous":{"title":"rpc-provider","level":"1.3","depth":1,"path":"rpc-provider/README.md","ref":"rpc-provider/README.md","articles":[{"title":"HttpProvider","level":"1.3.1","depth":2,"path":"rpc-provider/classes/_http_index_.httpprovider.md","ref":"rpc-provider/classes/_http_index_.httpprovider.md","articles":[]},{"title":"WsProvider","level":"1.3.2","depth":2,"path":"rpc-provider/classes/_ws_index_.wsprovider.md","ref":"rpc-provider/classes/_ws_index_.wsprovider.md","articles":[]}]},"dir":"ltr"},"config":{"plugins":["include-codeblock","mermaid-gb3","-highlight","sunlight-highlighter"],"root":"docs","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"sunlight-highlighter":{"theme":"gitbook","lineNumbers":false},"include-codeblock":{"check":false,"edit":false,"lang":"","fixlang":false,"template":"default","theme":"chrome","unindent":false},"mermaid-gb3":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Polkadot API Book","gitbook":">=2.4.0"},"file":{"path":"rpc-provider/classes/_http_index_.httpprovider.md","mtime":"2018-10-11T19:00:13.361Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-10-11T19:01:29.429Z"},"basePath":"../..","book":{"language":""}});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
|
||||
|
||||
@polkadot/rpc-provider/https
|
||||
============================
|
||||
*__name__*: HttpProvider
|
||||
|
||||
*__summary__*: The HTTP Provider allows sending requests using HTTP to a HTTP RPC server TCP port.
|
||||
@@ -8,11 +10,11 @@
|
||||
|
||||
*__example__*:
|
||||
```javascript
|
||||
import Rpc from '@polkadot/rpc-core';
|
||||
import Api from '@polkadot/api/promise';
|
||||
import HttpProvider from '@polkadot/rpc-provider/http';
|
||||
|
||||
const provider = new HttpProvider('http://127.0.0.1:9933');
|
||||
const api = new Rpc(provider);
|
||||
const api = new Api(provider);
|
||||
```
|
||||
|
||||
*__see__*: [WsProvider](_ws_index_.wsprovider.md)
|
||||
@@ -31,15 +33,15 @@ const api = new Rpc(provider);
|
||||
|
||||
## constructor
|
||||
|
||||
⊕ **new HttpProvider**(endpoint: *`string`*): [HttpProvider](_http_index_.httpprovider.md)
|
||||
⊕ **new HttpProvider**(endpoint?: *`string`*): [HttpProvider](_http_index_.httpprovider.md)
|
||||
|
||||
*Defined in [http/index.ts:40](https://github.com/polkadot-js/api/blob/e103e98/packages/rpc-provider/src/http/index.ts#L40)*
|
||||
*Defined in [http/index.ts:43](https://github.com/polkadot-js/api/blob/2b88a8f/packages/rpc-provider/src/http/index.ts#L43)*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
| Param | Type | Description |
|
||||
| ------ | ------ | ------ |
|
||||
| endpoint | `string` | The endpoint url starting with http:// |
|
||||
| Param | Type | Default value | Description |
|
||||
| ------ | ------ | ------ | ------ |
|
||||
| `Default value` endpoint | `string` | defaults.HTTP_URL | The endpoint url starting with http:// |
|
||||
|
||||
**Returns:** [HttpProvider](_http_index_.httpprovider.md)
|
||||
|
||||
@@ -53,7 +55,7 @@ ___
|
||||
|
||||
▸ **isConnected**(): `boolean`
|
||||
|
||||
*Defined in [http/index.ts:57](https://github.com/polkadot-js/api/blob/e103e98/packages/rpc-provider/src/http/index.ts#L57)*
|
||||
*Defined in [http/index.ts:60](https://github.com/polkadot-js/api/blob/2b88a8f/packages/rpc-provider/src/http/index.ts#L60)*
|
||||
|
||||
*__summary__*: Whether the node is connected or not.
|
||||
|
||||
@@ -67,7 +69,7 @@ ___
|
||||
|
||||
▸ **on**(type: *`ProviderInterface$Emitted`*, sub: *`ProviderInterface$EmitCb`*): `void`
|
||||
|
||||
*Defined in [http/index.ts:65](https://github.com/polkadot-js/api/blob/e103e98/packages/rpc-provider/src/http/index.ts#L65)*
|
||||
*Defined in [http/index.ts:68](https://github.com/polkadot-js/api/blob/2b88a8f/packages/rpc-provider/src/http/index.ts#L68)*
|
||||
|
||||
*__summary__*: Events are not supported with the HttpProvider, see [WsProvider](_ws_index_.wsprovider.md).
|
||||
|
||||
@@ -89,7 +91,7 @@ ___
|
||||
|
||||
▸ **send**(method: *`string`*, params: *`Array`<`any`>*): `Promise`<`any`>
|
||||
|
||||
*Defined in [http/index.ts:72](https://github.com/polkadot-js/api/blob/e103e98/packages/rpc-provider/src/http/index.ts#L72)*
|
||||
*Defined in [http/index.ts:75](https://github.com/polkadot-js/api/blob/2b88a8f/packages/rpc-provider/src/http/index.ts#L75)*
|
||||
|
||||
*__summary__*: Send HTTP POST Request with Body to configured HTTP Endpoint.
|
||||
|
||||
@@ -109,7 +111,7 @@ ___
|
||||
|
||||
▸ **subscribe**(types: *`string`*, method: *`string`*, params: *`Array`<`any`>*, cb: *`ProviderInterface$Callback`*): `Promise`<`number`>
|
||||
|
||||
*Defined in [http/index.ts:94](https://github.com/polkadot-js/api/blob/e103e98/packages/rpc-provider/src/http/index.ts#L94)*
|
||||
*Defined in [http/index.ts:97](https://github.com/polkadot-js/api/blob/2b88a8f/packages/rpc-provider/src/http/index.ts#L97)*
|
||||
|
||||
*__summary__*: Subscriptions are not supported with the HttpProvider, see [WsProvider](_ws_index_.wsprovider.md).
|
||||
|
||||
@@ -131,7 +133,7 @@ ___
|
||||
|
||||
▸ **unsubscribe**(type: *`string`*, method: *`string`*, id: *`number`*): `Promise`<`boolean`>
|
||||
|
||||
*Defined in [http/index.ts:103](https://github.com/polkadot-js/api/blob/e103e98/packages/rpc-provider/src/http/index.ts#L103)*
|
||||
*Defined in [http/index.ts:106](https://github.com/polkadot-js/api/blob/2b88a8f/packages/rpc-provider/src/http/index.ts#L106)*
|
||||
|
||||
*__summary__*: Subscriptions are not supported with the HttpProvider, see [WsProvider](_ws_index_.wsprovider.md).
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@
|
||||
<link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">
|
||||
|
||||
|
||||
<link rel="next" href="../../rpc-core/" />
|
||||
<link rel="next" href="../../examples-rpc/" />
|
||||
|
||||
|
||||
<link rel="prev" href="_http_index_.httpprovider.html" />
|
||||
@@ -195,70 +195,6 @@
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4" data-path="../../rpc-core/">
|
||||
|
||||
<a href="../../rpc-core/">
|
||||
|
||||
|
||||
rpc-core
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
<ul class="articles">
|
||||
|
||||
|
||||
<li class="chapter " data-level="1.4.1" data-path="../../rpc-core/classes/_index_.rpc.html">
|
||||
|
||||
<a href="../../rpc-core/classes/_index_.rpc.html">
|
||||
|
||||
|
||||
Rpc
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.5" data-path="../../rpc-rx/">
|
||||
|
||||
<a href="../../rpc-rx/">
|
||||
|
||||
|
||||
rpc-rx
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
<ul class="articles">
|
||||
|
||||
|
||||
<li class="chapter " data-level="1.5.1" data-path="../../rpc-rx/classes/_index_.rpcrx.html">
|
||||
|
||||
<a href="../../rpc-rx/classes/_index_.rpcrx.html">
|
||||
|
||||
|
||||
RpcRx
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
@@ -428,15 +364,16 @@
|
||||
|
||||
<section class="normal markdown-section">
|
||||
|
||||
<p><em><strong>name</strong></em>: WsProvider</p>
|
||||
<h1 id="polkadotrpc-providerws">@polkadot/rpc-provider/ws</h1>
|
||||
<p><em><strong>name</strong></em>: WsProvider</p>
|
||||
<p><em><strong>summary</strong></em>: The WebSocket Provider allows sending requests using WebSocket to a WebSocket RPC server TCP port.</p>
|
||||
<p><em><strong>description</strong></em>: Unlike the <a href="_http_index_.httpprovider.html">HttpProvider</a>, it does support subscriptions and allows listening to events such as new blocks or balance changes.</p>
|
||||
<p><em><strong>example</strong></em>: </p>
|
||||
<pre><code class="lang-javascript"><div class="sunlight-container sunlight-theme-gitbook"><div class="sunlight-code-container"><pre class="sunlight-highlight-javascript sunlight-highlighted"><span class="sunlight-javascript"><span class="sunlight-reservedWord">import</span> <span class="sunlight-ident">Rpc</span> <span class="sunlight-ident">from</span> <span class="sunlight-string">'@polkadot/rpc-core'</span><span class="sunlight-punctuation">;</span>
|
||||
<pre><code class="lang-javascript"><div class="sunlight-container sunlight-theme-gitbook"><div class="sunlight-code-container"><pre class="sunlight-highlight-javascript sunlight-highlighted"><span class="sunlight-javascript"><span class="sunlight-reservedWord">import</span> <span class="sunlight-ident">Api</span> <span class="sunlight-ident">from</span> <span class="sunlight-string">'@polkadot/api/promise'</span><span class="sunlight-punctuation">;</span>
|
||||
<span class="sunlight-reservedWord">import</span> <span class="sunlight-ident">WsProvider</span> <span class="sunlight-ident">from</span> <span class="sunlight-string">'@polkadot/rpc-provider/ws'</span><span class="sunlight-punctuation">;</span>
|
||||
|
||||
<span class="sunlight-reservedWord">const</span> <span class="sunlight-ident">provider</span> <span class="sunlight-operator">=</span> <span class="sunlight-keyword">new</span> <span class="sunlight-ident">WsProvider</span><span class="sunlight-punctuation">(</span><span class="sunlight-string">'ws://127.0.0.1:9944'</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
|
||||
<span class="sunlight-reservedWord">const</span> <span class="sunlight-ident">api</span> <span class="sunlight-operator">=</span> <span class="sunlight-keyword">new</span> <span class="sunlight-ident">Rpc</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">provider</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
|
||||
<span class="sunlight-reservedWord">const</span> <span class="sunlight-ident">api</span> <span class="sunlight-operator">=</span> <span class="sunlight-keyword">new</span> <span class="sunlight-ident">Api</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">provider</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
|
||||
</span></pre></div></div></code></pre>
|
||||
<p><em><strong>see</strong></em>: <a href="_http_index_.httpprovider.html">HttpProvider</a></p>
|
||||
<h1 id="hierarchy">Hierarchy</h1>
|
||||
@@ -448,8 +385,8 @@
|
||||
<h1 id="constructors">Constructors</h1>
|
||||
<p><a id="constructor"></a></p>
|
||||
<h2 id="constructor">constructor</h2>
|
||||
<p>⊕ <strong>new WsProvider</strong>(endpoint: <em><code>string</code></em>, autoConnect?: <em><code>boolean</code></em>): <a href="_ws_index_.wsprovider.html">WsProvider</a></p>
|
||||
<p><em>Defined in <a href="https://github.com/polkadot-js/api/blob/e103e98/packages/rpc-provider/src/ws/index.ts#L74" target="_blank">ws/index.ts:74</a></em></p>
|
||||
<p>⊕ <strong>new WsProvider</strong>(endpoint?: <em><code>string</code></em>, autoConnect?: <em><code>boolean</code></em>): <a href="_ws_index_.wsprovider.html">WsProvider</a></p>
|
||||
<p><em>Defined in <a href="https://github.com/polkadot-js/api/blob/2b88a8f/packages/rpc-provider/src/ws/index.ts#L77" target="_blank">ws/index.ts:77</a></em></p>
|
||||
<p><strong>Parameters:</strong></p>
|
||||
<table>
|
||||
<thead>
|
||||
@@ -462,9 +399,9 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>endpoint</td>
|
||||
<td><code>Default value</code> endpoint</td>
|
||||
<td><code>string</code></td>
|
||||
<td>-</td>
|
||||
<td>defaults.WS_URL</td>
|
||||
<td>The endpoint url. Usually `ws://ip:9944` or `wss://ip:9944`</td>
|
||||
</tr>
|
||||
<tr>
|
||||
@@ -481,7 +418,7 @@
|
||||
<p><a id="connect"></a></p>
|
||||
<h2 id="connect">connect</h2>
|
||||
<p>▸ <strong>connect</strong>(): <code>void</code></p>
|
||||
<p><em>Defined in <a href="https://github.com/polkadot-js/api/blob/e103e98/packages/rpc-provider/src/ws/index.ts#L104" target="_blank">ws/index.ts:104</a></em></p>
|
||||
<p><em>Defined in <a href="https://github.com/polkadot-js/api/blob/2b88a8f/packages/rpc-provider/src/ws/index.ts#L107" target="_blank">ws/index.ts:107</a></em></p>
|
||||
<p><em><strong>summary</strong></em>: Manually connect</p>
|
||||
<p><em><strong>description</strong></em>: The <a href="_ws_index_.wsprovider.html">WsProvider</a> connects automatically by default, however if you decided otherwise, you may connect manually using this method.</p>
|
||||
<p><strong>Returns:</strong> <code>void</code></p>
|
||||
@@ -489,7 +426,7 @@
|
||||
<p><a id="isconnected"></a></p>
|
||||
<h2 id="isconnected">isConnected</h2>
|
||||
<p>▸ <strong>isConnected</strong>(): <code>boolean</code></p>
|
||||
<p><em>Defined in <a href="https://github.com/polkadot-js/api/blob/e103e98/packages/rpc-provider/src/ws/index.ts#L121" target="_blank">ws/index.ts:121</a></em></p>
|
||||
<p><em>Defined in <a href="https://github.com/polkadot-js/api/blob/2b88a8f/packages/rpc-provider/src/ws/index.ts#L124" target="_blank">ws/index.ts:124</a></em></p>
|
||||
<p><em><strong>summary</strong></em>: Whether the node is connected or not.</p>
|
||||
<p><strong>Returns:</strong> <code>boolean</code>
|
||||
true if connected</p>
|
||||
@@ -497,7 +434,7 @@ true if connected</p>
|
||||
<p><a id="on"></a></p>
|
||||
<h2 id="on">on</h2>
|
||||
<p>▸ <strong>on</strong>(type: <em><code>ProviderInterface$Emitted</code></em>, sub: <em><code>ProviderInterface$EmitCb</code></em>): <code>void</code></p>
|
||||
<p><em>Defined in <a href="https://github.com/polkadot-js/api/blob/e103e98/packages/rpc-provider/src/ws/index.ts#L130" target="_blank">ws/index.ts:130</a></em></p>
|
||||
<p><em>Defined in <a href="https://github.com/polkadot-js/api/blob/2b88a8f/packages/rpc-provider/src/ws/index.ts#L133" target="_blank">ws/index.ts:133</a></em></p>
|
||||
<p><em><strong>summary</strong></em>: Listens on events after having subscribed using the <a href="_ws_index_.wsprovider.html#subscribe">subscribe</a> function.</p>
|
||||
<p><strong>Parameters:</strong></p>
|
||||
<table>
|
||||
@@ -526,7 +463,7 @@ true if connected</p>
|
||||
<p><a id="send"></a></p>
|
||||
<h2 id="send">send</h2>
|
||||
<p>▸ <strong>send</strong>(method: <em><code>string</code></em>, params: <em><code>Array</code><<code>any</code>></em>, subscription?: <em><code>SubscriptionHandler</code></em>): <code>Promise</code><<code>any</code>></p>
|
||||
<p><em>Defined in <a href="https://github.com/polkadot-js/api/blob/e103e98/packages/rpc-provider/src/ws/index.ts#L137" target="_blank">ws/index.ts:137</a></em></p>
|
||||
<p><em>Defined in <a href="https://github.com/polkadot-js/api/blob/2b88a8f/packages/rpc-provider/src/ws/index.ts#L140" target="_blank">ws/index.ts:140</a></em></p>
|
||||
<p><em><strong>summary</strong></em>: Send JSON data using WebSockets to configured HTTP Endpoint or queue.</p>
|
||||
<p><strong>Parameters:</strong></p>
|
||||
<table>
|
||||
@@ -556,7 +493,7 @@ true if connected</p>
|
||||
<p><a id="subscribe"></a></p>
|
||||
<h2 id="subscribe">subscribe</h2>
|
||||
<p>▸ <strong>subscribe</strong>(type: <em><code>string</code></em>, method: <em><code>string</code></em>, params: <em><code>Array</code><<code>any</code>></em>, callback: <em><code>ProviderInterface$Callback</code></em>): <code>Promise</code><<code>number</code>></p>
|
||||
<p><em>Defined in <a href="https://github.com/polkadot-js/api/blob/e103e98/packages/rpc-provider/src/ws/index.ts#L193" target="_blank">ws/index.ts:193</a></em></p>
|
||||
<p><em>Defined in <a href="https://github.com/polkadot-js/api/blob/2b88a8f/packages/rpc-provider/src/ws/index.ts#L196" target="_blank">ws/index.ts:196</a></em></p>
|
||||
<p><em><strong>name</strong></em>: subscribe</p>
|
||||
<p><em><strong>summary</strong></em>: Allows subscribing to a specific event.</p>
|
||||
<p><em><strong>example</strong></em>: </p>
|
||||
@@ -607,7 +544,7 @@ Promise resolving to the dd of the subscription you can use with [[unsubscribe]]
|
||||
<p><a id="unsubscribe"></a></p>
|
||||
<h2 id="unsubscribe">unsubscribe</h2>
|
||||
<p>▸ <strong>unsubscribe</strong>(type: <em><code>string</code></em>, method: <em><code>string</code></em>, id: <em><code>number</code></em>): <code>Promise</code><<code>boolean</code>></p>
|
||||
<p><em>Defined in <a href="https://github.com/polkadot-js/api/blob/e103e98/packages/rpc-provider/src/ws/index.ts#L202" target="_blank">ws/index.ts:202</a></em></p>
|
||||
<p><em>Defined in <a href="https://github.com/polkadot-js/api/blob/2b88a8f/packages/rpc-provider/src/ws/index.ts#L205" target="_blank">ws/index.ts:205</a></em></p>
|
||||
<p><em><strong>summary</strong></em>: Allows unsubscribing to subscriptions made with <a href="_ws_index_.wsprovider.html#subscribe">subscribe</a>.</p>
|
||||
<p><strong>Parameters:</strong></p>
|
||||
<table>
|
||||
@@ -666,7 +603,7 @@ Promise resolving to the dd of the subscription you can use with [[unsubscribe]]
|
||||
</a>
|
||||
|
||||
|
||||
<a href="../../rpc-core/" class="navigation navigation-next " aria-label="Next page: rpc-core">
|
||||
<a href="../../examples-rpc/" class="navigation navigation-next " aria-label="Next page: RPC">
|
||||
<i class="fa fa-angle-right"></i>
|
||||
</a>
|
||||
|
||||
@@ -677,7 +614,7 @@ Promise resolving to the dd of the subscription you can use with [[unsubscribe]]
|
||||
<script>
|
||||
var gitbook = gitbook || [];
|
||||
gitbook.push(function() {
|
||||
gitbook.page.hasChanged({"page":{"title":"WsProvider","level":"1.3.2","depth":2,"next":{"title":"rpc-core","level":"1.4","depth":1,"path":"rpc-core/README.md","ref":"rpc-core/README.md","articles":[{"title":"Rpc","level":"1.4.1","depth":2,"path":"rpc-core/classes/_index_.rpc.md","ref":"rpc-core/classes/_index_.rpc.md","articles":[]}]},"previous":{"title":"HttpProvider","level":"1.3.1","depth":2,"path":"rpc-provider/classes/_http_index_.httpprovider.md","ref":"rpc-provider/classes/_http_index_.httpprovider.md","articles":[]},"dir":"ltr"},"config":{"plugins":["include-codeblock","mermaid-gb3","-highlight","sunlight-highlighter"],"root":"docs","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"sunlight-highlighter":{"theme":"gitbook","lineNumbers":false},"include-codeblock":{"check":false,"edit":false,"lang":"","fixlang":false,"template":"default","theme":"chrome","unindent":false},"mermaid-gb3":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Polkadot API Book","gitbook":">=2.4.0"},"file":{"path":"rpc-provider/classes/_ws_index_.wsprovider.md","mtime":"2018-10-11T16:51:08.089Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-10-11T16:52:14.838Z"},"basePath":"../..","book":{"language":""}});
|
||||
gitbook.page.hasChanged({"page":{"title":"WsProvider","level":"1.3.2","depth":2,"next":{"title":"RPC","level":"2.1","depth":1,"path":"examples-rpc/README.md","ref":"examples-rpc/README.md","articles":[{"title":"Simple connect","level":"2.1.1","depth":2,"path":"examples-rpc/01_simple_connect/README.md","ref":"examples-rpc/01_simple_connect/README.md","articles":[]},{"title":"Listen to blocks","level":"2.1.2","depth":2,"path":"examples-rpc/02_listen_to_blocks/README.md","ref":"examples-rpc/02_listen_to_blocks/README.md","articles":[]},{"title":"Listen to balance change","level":"2.1.3","depth":2,"path":"examples-rpc/03_listen_to_balance_change/README.md","ref":"examples-rpc/03_listen_to_balance_change/README.md","articles":[]},{"title":"Generate Accounts","level":"2.1.4","depth":2,"path":"examples-rpc/04_generate_account/README.md","ref":"examples-rpc/04_generate_account/README.md","articles":[]},{"title":"Read Storage","level":"2.1.5","depth":2,"path":"examples-rpc/05_read_storage/README.md","ref":"examples-rpc/05_read_storage/README.md","articles":[]},{"title":"Craft Extrinsic","level":"2.1.6","depth":2,"path":"examples-rpc/06_craft_extrinsic/README.md","ref":"examples-rpc/06_craft_extrinsic/README.md","articles":[]},{"title":"Transfer DOTs","level":"2.1.7","depth":2,"path":"examples-rpc/07_transfer_dots/README.md","ref":"examples-rpc/07_transfer_dots/README.md","articles":[]}]},"previous":{"title":"HttpProvider","level":"1.3.1","depth":2,"path":"rpc-provider/classes/_http_index_.httpprovider.md","ref":"rpc-provider/classes/_http_index_.httpprovider.md","articles":[]},"dir":"ltr"},"config":{"plugins":["include-codeblock","mermaid-gb3","-highlight","sunlight-highlighter"],"root":"docs","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"sunlight-highlighter":{"theme":"gitbook","lineNumbers":false},"include-codeblock":{"check":false,"edit":false,"lang":"","fixlang":false,"template":"default","theme":"chrome","unindent":false},"mermaid-gb3":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Polkadot API Book","gitbook":">=2.4.0"},"file":{"path":"rpc-provider/classes/_ws_index_.wsprovider.md","mtime":"2018-10-11T19:00:13.433Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-10-11T19:01:29.429Z"},"basePath":"../..","book":{"language":""}});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
|
||||
|
||||
@polkadot/rpc-provider/ws
|
||||
=========================
|
||||
*__name__*: WsProvider
|
||||
|
||||
*__summary__*: The WebSocket Provider allows sending requests using WebSocket to a WebSocket RPC server TCP port.
|
||||
@@ -8,11 +10,11 @@
|
||||
|
||||
*__example__*:
|
||||
```javascript
|
||||
import Rpc from '@polkadot/rpc-core';
|
||||
import Api from '@polkadot/api/promise';
|
||||
import WsProvider from '@polkadot/rpc-provider/ws';
|
||||
|
||||
const provider = new WsProvider('ws://127.0.0.1:9944');
|
||||
const api = new Rpc(provider);
|
||||
const api = new Api(provider);
|
||||
```
|
||||
|
||||
*__see__*: [HttpProvider](_http_index_.httpprovider.md)
|
||||
@@ -31,15 +33,15 @@ const api = new Rpc(provider);
|
||||
|
||||
## constructor
|
||||
|
||||
⊕ **new WsProvider**(endpoint: *`string`*, autoConnect?: *`boolean`*): [WsProvider](_ws_index_.wsprovider.md)
|
||||
⊕ **new WsProvider**(endpoint?: *`string`*, autoConnect?: *`boolean`*): [WsProvider](_ws_index_.wsprovider.md)
|
||||
|
||||
*Defined in [ws/index.ts:74](https://github.com/polkadot-js/api/blob/e103e98/packages/rpc-provider/src/ws/index.ts#L74)*
|
||||
*Defined in [ws/index.ts:77](https://github.com/polkadot-js/api/blob/2b88a8f/packages/rpc-provider/src/ws/index.ts#L77)*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
| Param | Type | Default value | Description |
|
||||
| ------ | ------ | ------ | ------ |
|
||||
| endpoint | `string` | - | The endpoint url. Usually \`ws://ip:9944\` or \`wss://ip:9944\` |
|
||||
| `Default value` endpoint | `string` | defaults.WS_URL | The endpoint url. Usually \`ws://ip:9944\` or \`wss://ip:9944\` |
|
||||
| `Default value` autoConnect | `boolean` | true | Whether to connect automatically or not. |
|
||||
|
||||
**Returns:** [WsProvider](_ws_index_.wsprovider.md)
|
||||
@@ -54,7 +56,7 @@ ___
|
||||
|
||||
▸ **connect**(): `void`
|
||||
|
||||
*Defined in [ws/index.ts:104](https://github.com/polkadot-js/api/blob/e103e98/packages/rpc-provider/src/ws/index.ts#L104)*
|
||||
*Defined in [ws/index.ts:107](https://github.com/polkadot-js/api/blob/2b88a8f/packages/rpc-provider/src/ws/index.ts#L107)*
|
||||
|
||||
*__summary__*: Manually connect
|
||||
|
||||
@@ -69,7 +71,7 @@ ___
|
||||
|
||||
▸ **isConnected**(): `boolean`
|
||||
|
||||
*Defined in [ws/index.ts:121](https://github.com/polkadot-js/api/blob/e103e98/packages/rpc-provider/src/ws/index.ts#L121)*
|
||||
*Defined in [ws/index.ts:124](https://github.com/polkadot-js/api/blob/2b88a8f/packages/rpc-provider/src/ws/index.ts#L124)*
|
||||
|
||||
*__summary__*: Whether the node is connected or not.
|
||||
|
||||
@@ -83,7 +85,7 @@ ___
|
||||
|
||||
▸ **on**(type: *`ProviderInterface$Emitted`*, sub: *`ProviderInterface$EmitCb`*): `void`
|
||||
|
||||
*Defined in [ws/index.ts:130](https://github.com/polkadot-js/api/blob/e103e98/packages/rpc-provider/src/ws/index.ts#L130)*
|
||||
*Defined in [ws/index.ts:133](https://github.com/polkadot-js/api/blob/2b88a8f/packages/rpc-provider/src/ws/index.ts#L133)*
|
||||
|
||||
*__summary__*: Listens on events after having subscribed using the [subscribe](_ws_index_.wsprovider.md#subscribe) function.
|
||||
|
||||
@@ -103,7 +105,7 @@ ___
|
||||
|
||||
▸ **send**(method: *`string`*, params: *`Array`<`any`>*, subscription?: *`SubscriptionHandler`*): `Promise`<`any`>
|
||||
|
||||
*Defined in [ws/index.ts:137](https://github.com/polkadot-js/api/blob/e103e98/packages/rpc-provider/src/ws/index.ts#L137)*
|
||||
*Defined in [ws/index.ts:140](https://github.com/polkadot-js/api/blob/2b88a8f/packages/rpc-provider/src/ws/index.ts#L140)*
|
||||
|
||||
*__summary__*: Send JSON data using WebSockets to configured HTTP Endpoint or queue.
|
||||
|
||||
@@ -124,7 +126,7 @@ ___
|
||||
|
||||
▸ **subscribe**(type: *`string`*, method: *`string`*, params: *`Array`<`any`>*, callback: *`ProviderInterface$Callback`*): `Promise`<`number`>
|
||||
|
||||
*Defined in [ws/index.ts:193](https://github.com/polkadot-js/api/blob/e103e98/packages/rpc-provider/src/ws/index.ts#L193)*
|
||||
*Defined in [ws/index.ts:196](https://github.com/polkadot-js/api/blob/2b88a8f/packages/rpc-provider/src/ws/index.ts#L196)*
|
||||
|
||||
*__name__*: subscribe
|
||||
|
||||
@@ -161,7 +163,7 @@ ___
|
||||
|
||||
▸ **unsubscribe**(type: *`string`*, method: *`string`*, id: *`number`*): `Promise`<`boolean`>
|
||||
|
||||
*Defined in [ws/index.ts:202](https://github.com/polkadot-js/api/blob/e103e98/packages/rpc-provider/src/ws/index.ts#L202)*
|
||||
*Defined in [ws/index.ts:205](https://github.com/polkadot-js/api/blob/2b88a8f/packages/rpc-provider/src/ws/index.ts#L205)*
|
||||
|
||||
*__summary__*: Allows unsubscribing to subscriptions made with [subscribe](_ws_index_.wsprovider.md#subscribe).
|
||||
|
||||
|
||||
@@ -195,70 +195,6 @@
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4" data-path="../rpc-core/">
|
||||
|
||||
<a href="../rpc-core/">
|
||||
|
||||
|
||||
rpc-core
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
<ul class="articles">
|
||||
|
||||
|
||||
<li class="chapter " data-level="1.4.1" data-path="../rpc-core/classes/_index_.rpc.html">
|
||||
|
||||
<a href="../rpc-core/classes/_index_.rpc.html">
|
||||
|
||||
|
||||
Rpc
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.5" data-path="../rpc-rx/">
|
||||
|
||||
<a href="../rpc-rx/">
|
||||
|
||||
|
||||
rpc-rx
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
<ul class="articles">
|
||||
|
||||
|
||||
<li class="chapter " data-level="1.5.1" data-path="../rpc-rx/classes/_index_.rpcrx.html">
|
||||
|
||||
<a href="../rpc-rx/classes/_index_.rpcrx.html">
|
||||
|
||||
|
||||
RpcRx
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
@@ -429,17 +365,30 @@
|
||||
<section class="normal markdown-section">
|
||||
|
||||
<h1 id="polkadotrpc-provider">@polkadot/rpc-provider</h1>
|
||||
<p>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.</p>
|
||||
<p>Generic transport providers to handle the transport of method calls to and from Polkadot clients from applications interacting with it. It provides an interface to making RPC class and is 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, rather only passed to a higher-level interface.</p>
|
||||
<h2 id="provider-selection">Provider Selection</h2>
|
||||
<p>There are two flavours of the providers provided, one allowing for using HTTP as a transport machanism, the other using WebSockets. It is generally recommended to use the <a href="classes/_ws_index_.wsprovider.html">WsProvider</a> since in addition to standard calls, it allows for subscriptions where all changes to state can be pushed from the node to the client.</p>
|
||||
<p>Both providers are usable (as is the API), in both browser-based and Node.js environments. Polyfills for unsupported functionality are automatically applied based on feature-detection.</p>
|
||||
<h2 id="usage">Usage</h2>
|
||||
<p>Installation -</p>
|
||||
<pre><code>yarn add @polkadot/rpc-provider
|
||||
</code></pre><p>Initialisation -</p>
|
||||
<pre><code class="lang-js"><div class="sunlight-container sunlight-theme-gitbook"><div class="sunlight-code-container"><pre class="sunlight-highlight-javascript sunlight-highlighted"><span class="sunlight-javascript"><span class="sunlight-reservedWord">import</span> <span class="sunlight-ident">WsProvider</span> <span class="sunlight-ident">from</span> <span class="sunlight-string">'@polkadot/rpc-provider/ws'</span><span class="sunlight-punctuation">;</span>
|
||||
</code></pre><p>WebSocket Initialisation -</p>
|
||||
<pre><code class="lang-javascript"><div class="sunlight-container sunlight-theme-gitbook"><div class="sunlight-code-container"><pre class="sunlight-highlight-javascript sunlight-highlighted"><span class="sunlight-javascript"><span class="sunlight-reservedWord">import</span> <span class="sunlight-ident">WsProvider</span> <span class="sunlight-ident">from</span> <span class="sunlight-string">'@polkadot/rpc-provider/ws'</span><span class="sunlight-punctuation">;</span>
|
||||
|
||||
<span class="sunlight-reservedWord">const</span> <span class="sunlight-ident">provider</span> <span class="sunlight-operator">=</span> <span class="sunlight-keyword">new</span> <span class="sunlight-ident">WsProvider</span><span class="sunlight-punctuation">(</span><span class="sunlight-string">'http://127.0.0.1:9944'</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
|
||||
<span class="sunlight-comment">// this is the actual default endpoint</span>
|
||||
<span class="sunlight-reservedWord">const</span> <span class="sunlight-ident">provider</span> <span class="sunlight-operator">=</span> <span class="sunlight-keyword">new</span> <span class="sunlight-ident">WsProvider</span><span class="sunlight-punctuation">(</span><span class="sunlight-string">'ws://127.0.0.1:9944'</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
|
||||
<span class="sunlight-reservedWord">const</span> <span class="sunlight-ident">version</span> <span class="sunlight-operator">=</span> <span class="sunlight-ident">await</span> <span class="sunlight-ident">provider</span><span class="sunlight-operator">.</span><span class="sunlight-ident">send</span><span class="sunlight-punctuation">(</span><span class="sunlight-string">'client_version'</span><span class="sunlight-punctuation">,</span> <span class="sunlight-punctuation">[</span><span class="sunlight-punctuation">]</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
|
||||
|
||||
<span class="sunlight-ident">console</span><span class="sunlight-operator">.</span><span class="sunlight-ident">log</span><span class="sunlight-punctuation">(</span><span class="sunlight-string">'clientVersion'</span><span class="sunlight-punctuation">,</span> <span class="sunlight-ident">version</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
|
||||
<span class="sunlight-ident">console</span><span class="sunlight-operator">.</span><span class="sunlight-ident">log</span><span class="sunlight-punctuation">(</span><span class="sunlight-string">'client version'</span><span class="sunlight-punctuation">,</span> <span class="sunlight-ident">version</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
|
||||
</span></pre></div></div></code></pre>
|
||||
<p>HTTP Initialisation -</p>
|
||||
<pre><code class="lang-javascript"><div class="sunlight-container sunlight-theme-gitbook"><div class="sunlight-code-container"><pre class="sunlight-highlight-javascript sunlight-highlighted"><span class="sunlight-javascript"><span class="sunlight-reservedWord">import</span> <span class="sunlight-punctuation">{</span> <span class="sunlight-ident">HttpProvider</span> <span class="sunlight-punctuation">}</span> <span class="sunlight-ident">from</span> <span class="sunlight-string">'@polkadot/rpc-provider'</span><span class="sunlight-punctuation">;</span>
|
||||
|
||||
<span class="sunlight-comment">// this is the actual default endpoint</span>
|
||||
<span class="sunlight-reservedWord">const</span> <span class="sunlight-ident">provider</span> <span class="sunlight-operator">=</span> <span class="sunlight-keyword">new</span> <span class="sunlight-ident">HttpProvider</span><span class="sunlight-punctuation">(</span><span class="sunlight-string">'http://127.0.0.1:9933'</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
|
||||
<span class="sunlight-reservedWord">const</span> <span class="sunlight-ident">version</span> <span class="sunlight-operator">=</span> <span class="sunlight-ident">await</span> <span class="sunlight-ident">provider</span><span class="sunlight-operator">.</span><span class="sunlight-ident">send</span><span class="sunlight-punctuation">(</span><span class="sunlight-string">'chain_getBlockHash'</span><span class="sunlight-punctuation">,</span> <span class="sunlight-punctuation">[</span><span class="sunlight-punctuation">]</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
|
||||
|
||||
<span class="sunlight-ident">console</span><span class="sunlight-operator">.</span><span class="sunlight-ident">log</span><span class="sunlight-punctuation">(</span><span class="sunlight-string">'latest block Hash'</span><span class="sunlight-punctuation">,</span> <span class="sunlight-ident">hash</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
|
||||
</span></pre></div></div></code></pre>
|
||||
|
||||
|
||||
@@ -484,7 +433,7 @@
|
||||
<script>
|
||||
var gitbook = gitbook || [];
|
||||
gitbook.push(function() {
|
||||
gitbook.page.hasChanged({"page":{"title":"rpc-provider","level":"1.3","depth":1,"next":{"title":"HttpProvider","level":"1.3.1","depth":2,"path":"rpc-provider/classes/_http_index_.httpprovider.md","ref":"rpc-provider/classes/_http_index_.httpprovider.md","articles":[]},"previous":{"title":"ApiRx","level":"1.2.2","depth":2,"path":"api/classes/_rx_index_.apirx.md","ref":"api/classes/_rx_index_.apirx.md","articles":[]},"dir":"ltr"},"config":{"plugins":["include-codeblock","mermaid-gb3","-highlight","sunlight-highlighter"],"root":"docs","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"sunlight-highlighter":{"theme":"gitbook","lineNumbers":false},"include-codeblock":{"check":false,"edit":false,"lang":"","fixlang":false,"template":"default","theme":"chrome","unindent":false},"mermaid-gb3":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Polkadot API Book","gitbook":">=2.4.0"},"file":{"path":"rpc-provider/README.md","mtime":"2018-10-11T16:51:07.869Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-10-11T16:52:14.838Z"},"basePath":"..","book":{"language":""}});
|
||||
gitbook.page.hasChanged({"page":{"title":"rpc-provider","level":"1.3","depth":1,"next":{"title":"HttpProvider","level":"1.3.1","depth":2,"path":"rpc-provider/classes/_http_index_.httpprovider.md","ref":"rpc-provider/classes/_http_index_.httpprovider.md","articles":[]},"previous":{"title":"ApiRx","level":"1.2.2","depth":2,"path":"api/classes/_rx_index_.apirx.md","ref":"api/classes/_rx_index_.apirx.md","articles":[]},"dir":"ltr"},"config":{"plugins":["include-codeblock","mermaid-gb3","-highlight","sunlight-highlighter"],"root":"docs","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"sunlight-highlighter":{"theme":"gitbook","lineNumbers":false},"include-codeblock":{"check":false,"edit":false,"lang":"","fixlang":false,"template":"default","theme":"chrome","unindent":false},"mermaid-gb3":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Polkadot API Book","gitbook":">=2.4.0"},"file":{"path":"rpc-provider/README.md","mtime":"2018-10-11T19:00:13.197Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-10-11T19:01:29.429Z"},"basePath":"..","book":{"language":""}});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
▸ **decodeResponse**(self: *`RpcCoderState`*, response: *`JsonRpcResponse`*): `any`
|
||||
|
||||
*Defined in [coder/json/decodeResponse.ts:22](https://github.com/polkadot-js/api/blob/e103e98/packages/rpc-provider/src/coder/json/decodeResponse.ts#L22)*
|
||||
*Defined in [coder/json/decodeResponse.ts:22](https://github.com/polkadot-js/api/blob/2b88a8f/packages/rpc-provider/src/coder/json/decodeResponse.ts#L22)*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
▸ **encodeJson**(self: *`RpcCoderState`*, method: *`string`*, params: *`Array`<`any`>*): `string`
|
||||
|
||||
*Defined in [coder/json/encodeJson.ts:9](https://github.com/polkadot-js/api/blob/e103e98/packages/rpc-provider/src/coder/json/encodeJson.ts#L9)*
|
||||
*Defined in [coder/json/encodeJson.ts:9](https://github.com/polkadot-js/api/blob/2b88a8f/packages/rpc-provider/src/coder/json/encodeJson.ts#L9)*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
▸ **encodeObject**(self: *`RpcCoderState`*, method: *`string`*, params: *`Array`<`any`>*): `JsonRpcRequest`
|
||||
|
||||
*Defined in [coder/json/encodeObject.ts:8](https://github.com/polkadot-js/api/blob/e103e98/packages/rpc-provider/src/coder/json/encodeObject.ts#L8)*
|
||||
*Defined in [coder/json/encodeObject.ts:8](https://github.com/polkadot-js/api/blob/2b88a8f/packages/rpc-provider/src/coder/json/encodeObject.ts#L8)*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
▸ **rpcCoder**(): `RpcCoder`
|
||||
|
||||
*Defined in [coder/json/index.ts:12](https://github.com/polkadot-js/api/blob/e103e98/packages/rpc-provider/src/coder/json/index.ts#L12)*
|
||||
*Defined in [coder/json/index.ts:12](https://github.com/polkadot-js/api/blob/2b88a8f/packages/rpc-provider/src/coder/json/index.ts#L12)*
|
||||
|
||||
**Returns:** `RpcCoder`
|
||||
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
▸ **mockProvider**(): `ProviderInterface`
|
||||
|
||||
*Defined in [mock/index.ts:18](https://github.com/polkadot-js/api/blob/e103e98/packages/rpc-provider/src/mock/index.ts#L18)*
|
||||
*Defined in [mock/index.ts:18](https://github.com/polkadot-js/api/blob/2b88a8f/packages/rpc-provider/src/mock/index.ts#L18)*
|
||||
|
||||
A mock provider mainly used for testing.
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
▸ **mocks**(__namedParameters: *`object`*): `void`
|
||||
|
||||
*Defined in [mock/mocks.ts:63](https://github.com/polkadot-js/api/blob/e103e98/packages/rpc-provider/src/mock/mocks.ts#L63)*
|
||||
*Defined in [mock/mocks.ts:63](https://github.com/polkadot-js/api/blob/2b88a8f/packages/rpc-provider/src/mock/mocks.ts#L63)*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
▸ **on**(self: *`MockState`*, type: *`ProviderInterface$Emitted`*, sub: *`ProviderInterface$EmitCb`*): `void`
|
||||
|
||||
*Defined in [mock/on.ts:8](https://github.com/polkadot-js/api/blob/e103e98/packages/rpc-provider/src/mock/on.ts#L8)*
|
||||
*Defined in [mock/on.ts:8](https://github.com/polkadot-js/api/blob/2b88a8f/packages/rpc-provider/src/mock/on.ts#L8)*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
▸ **send**(__namedParameters: *`object`*, method: *`string`*, params: *`Array`<`any`>*): `Promise`<`any`>
|
||||
|
||||
*Defined in [mock/send.ts:7](https://github.com/polkadot-js/api/blob/e103e98/packages/rpc-provider/src/mock/send.ts#L7)*
|
||||
*Defined in [mock/send.ts:7](https://github.com/polkadot-js/api/blob/2b88a8f/packages/rpc-provider/src/mock/send.ts#L7)*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
▸ **state**(): `MockState`
|
||||
|
||||
*Defined in [mock/state.ts:38](https://github.com/polkadot-js/api/blob/e103e98/packages/rpc-provider/src/mock/state.ts#L38)*
|
||||
*Defined in [mock/state.ts:38](https://github.com/polkadot-js/api/blob/2b88a8f/packages/rpc-provider/src/mock/state.ts#L38)*
|
||||
|
||||
**Returns:** `MockState`
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
▸ **subscribe**(self: *`MockState`*, type: *`string`*, method: *`string`*, params: *`Array`<`any`>*): `Promise`<`number`>
|
||||
|
||||
*Defined in [mock/subscribe.ts:7](https://github.com/polkadot-js/api/blob/e103e98/packages/rpc-provider/src/mock/subscribe.ts#L7)*
|
||||
*Defined in [mock/subscribe.ts:7](https://github.com/polkadot-js/api/blob/2b88a8f/packages/rpc-provider/src/mock/subscribe.ts#L7)*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
▸ **unsubscribe**(self: *`MockState`*, type: *`string`*, name: *`string`*, id: *`number`*): `Promise`<`boolean`>
|
||||
|
||||
*Defined in [mock/unsubscribe.ts:7](https://github.com/polkadot-js/api/blob/e103e98/packages/rpc-provider/src/mock/unsubscribe.ts#L7)*
|
||||
*Defined in [mock/unsubscribe.ts:7](https://github.com/polkadot-js/api/blob/2b88a8f/packages/rpc-provider/src/mock/unsubscribe.ts#L7)*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
|
||||
Reference in New Issue
Block a user