Files
api/docs/rpc-provider/index.html
T
2018-10-12 14:50:57 +00:00

454 lines
17 KiB
HTML

<!DOCTYPE HTML>
<html lang="" >
<head>
<meta charset="UTF-8">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>rpc-provider · Polkadot API Book</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="description" content="">
<meta name="generator" content="GitBook 3.2.3">
<link rel="stylesheet" href="../gitbook/style.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-sunlight-highlighter/sunlight.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
<meta name="HandheldFriendly" content="true"/>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
<link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
<link rel="next" href="classes/_http_index_.httpprovider.html" />
<link rel="prev" href="../api/classes/_rx_index_.apirx.html" />
</head>
<body>
<div class="book">
<div class="book-summary">
<div id="book-search-input" role="search">
<input type="text" placeholder="Type to search" />
</div>
<nav role="navigation">
<ul class="summary">
<li class="header">Packages</li>
<li class="chapter " data-level="1.1" data-path="../">
<a href="../">
Introduction
</a>
</li>
<li class="chapter " data-level="1.2" data-path="../api/">
<a href="../api/">
api
</a>
<ul class="articles">
<li class="chapter " data-level="1.2.1" data-path="../api/classes/_promise_index_.apipromise.html">
<a href="../api/classes/_promise_index_.apipromise.html">
ApiPromise
</a>
</li>
<li class="chapter " data-level="1.2.2" data-path="../api/classes/_rx_index_.apirx.html">
<a href="../api/classes/_rx_index_.apirx.html">
ApiRx
</a>
</li>
</ul>
</li>
<li class="chapter active" data-level="1.3" data-path="./">
<a href="./">
rpc-provider
</a>
<ul class="articles">
<li class="chapter " data-level="1.3.1" data-path="classes/_http_index_.httpprovider.html">
<a href="classes/_http_index_.httpprovider.html">
HttpProvider
</a>
</li>
<li class="chapter " data-level="1.3.2" data-path="classes/_ws_index_.wsprovider.html">
<a href="classes/_ws_index_.wsprovider.html">
WsProvider
</a>
</li>
</ul>
</li>
<li class="header">Examples</li>
<li class="chapter " data-level="2.1" data-path="../examples/promise/">
<a href="../examples/promise/">
ApiPromise
</a>
<ul class="articles">
<li class="chapter " data-level="2.1.1" data-path="../examples/promise/01_simple_connect/">
<a href="../examples/promise/01_simple_connect/">
Simple connect
</a>
</li>
<li class="chapter " data-level="2.1.2" data-path="../examples/promise/02_listen_to_blocks/">
<a href="../examples/promise/02_listen_to_blocks/">
Listen to blocks
</a>
</li>
<li class="chapter " data-level="2.1.3" data-path="../examples/promise/03_listen_to_balance_change/">
<a href="../examples/promise/03_listen_to_balance_change/">
Listen to balance change
</a>
</li>
<li class="chapter " data-level="2.1.4" data-path="../examples/promise/05_read_storage/">
<a href="../examples/promise/05_read_storage/">
Read chain state
</a>
</li>
<li class="chapter " data-level="2.1.5" data-path="../examples/promise/07_transfer_dots/">
<a href="../examples/promise/07_transfer_dots/">
Make a transfer
</a>
</li>
</ul>
</li>
<li class="divider"></li>
<li>
<a href="https://www.gitbook.com" target="blank" class="gitbook-link">
Published with GitBook
</a>
</li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<div class="book-header" role="navigation">
<!-- Title -->
<h1>
<i class="fa fa-circle-o-notch fa-spin"></i>
<a href=".." >rpc-provider</a>
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<div id="book-search-results">
<div class="search-noresults">
<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. 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&apos;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>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>&#xA0;<span class="sunlight-ident">WsProvider</span>&#xA0;<span class="sunlight-ident">from</span>&#xA0;<span class="sunlight-string">&apos;@polkadot/rpc-provider/ws&apos;</span><span class="sunlight-punctuation">;</span>
<span class="sunlight-comment">//&#xA0;this&#xA0;is&#xA0;the&#xA0;actual&#xA0;default&#xA0;endpoint</span>
<span class="sunlight-reservedWord">const</span>&#xA0;<span class="sunlight-ident">provider</span>&#xA0;<span class="sunlight-operator">=</span>&#xA0;<span class="sunlight-keyword">new</span>&#xA0;<span class="sunlight-ident">WsProvider</span><span class="sunlight-punctuation">(</span><span class="sunlight-string">&apos;ws://127.0.0.1:9944&apos;</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
<span class="sunlight-reservedWord">const</span>&#xA0;<span class="sunlight-ident">version</span>&#xA0;<span class="sunlight-operator">=</span>&#xA0;<span class="sunlight-ident">await</span>&#xA0;<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">&apos;client_version&apos;</span><span class="sunlight-punctuation">,</span>&#xA0;<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">&apos;client&#xA0;version&apos;</span><span class="sunlight-punctuation">,</span>&#xA0;<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>&#xA0;<span class="sunlight-punctuation">{</span>&#xA0;<span class="sunlight-ident">HttpProvider</span>&#xA0;<span class="sunlight-punctuation">}</span>&#xA0;<span class="sunlight-ident">from</span>&#xA0;<span class="sunlight-string">&apos;@polkadot/rpc-provider&apos;</span><span class="sunlight-punctuation">;</span>
<span class="sunlight-comment">//&#xA0;this&#xA0;is&#xA0;the&#xA0;actual&#xA0;default&#xA0;endpoint</span>
<span class="sunlight-reservedWord">const</span>&#xA0;<span class="sunlight-ident">provider</span>&#xA0;<span class="sunlight-operator">=</span>&#xA0;<span class="sunlight-keyword">new</span>&#xA0;<span class="sunlight-ident">HttpProvider</span><span class="sunlight-punctuation">(</span><span class="sunlight-string">&apos;http://127.0.0.1:9933&apos;</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
<span class="sunlight-reservedWord">const</span>&#xA0;<span class="sunlight-ident">version</span>&#xA0;<span class="sunlight-operator">=</span>&#xA0;<span class="sunlight-ident">await</span>&#xA0;<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">&apos;chain_getBlockHash&apos;</span><span class="sunlight-punctuation">,</span>&#xA0;<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">&apos;latest&#xA0;block&#xA0;Hash&apos;</span><span class="sunlight-punctuation">,</span>&#xA0;<span class="sunlight-ident">hash</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
</span></pre></div></div></code></pre>
</section>
</div>
<div class="search-results">
<div class="has-results">
<h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
<ul class="search-results-list"></ul>
</div>
<div class="no-results">
<h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
</div>
</div>
</div>
</div>
</div>
</div>
<a href="../api/classes/_rx_index_.apirx.html" class="navigation navigation-prev " aria-label="Previous page: ApiRx">
<i class="fa fa-angle-left"></i>
</a>
<a href="classes/_http_index_.httpprovider.html" class="navigation navigation-next " aria-label="Next page: HttpProvider">
<i class="fa fa-angle-right"></i>
</a>
</div>
<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-12T14:49:44.997Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-10-12T14:50:50.178Z"},"basePath":"..","book":{"language":""}});
});
</script>
</div>
<script src="../gitbook/gitbook.js"></script>
<script src="../gitbook/theme.js"></script>
<script src="../gitbook/gitbook-plugin-mermaid-gb3/book/plugin.js"></script>
<script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
<script src="../gitbook/gitbook-plugin-search/search.js"></script>
<script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
<script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
<script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
<script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
<script src="../gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.min.js"></script>
</body>
</html>