[CI Skip] 0.31.28
This commit is contained in:
@@ -386,18 +386,18 @@
|
||||
|
||||
<h1 id="simple-connect">Simple Connect</h1>
|
||||
<p>The following example shows how to instantiate a Polkadot API object and use it to connect to a node.</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-comment">// required imports</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-comment">// Required imports</span>
|
||||
<span class="sunlight-reservedWord">const</span> <span class="sunlight-punctuation">{</span> <span class="sunlight-ident">ApiPromise</span> <span class="sunlight-punctuation">}</span> <span class="sunlight-operator">=</span> <span class="sunlight-ident">require</span><span class="sunlight-punctuation">(</span><span class="sunlight-string">'@polkadot/api'</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
|
||||
<span class="sunlight-reservedWord">const</span> <span class="sunlight-punctuation">{</span> <span class="sunlight-ident">WsProvider</span> <span class="sunlight-punctuation">}</span> <span class="sunlight-operator">=</span> <span class="sunlight-ident">require</span><span class="sunlight-punctuation">(</span><span class="sunlight-string">'@polkadot/rpc-provider'</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
|
||||
|
||||
<span class="sunlight-ident">async</span> <span class="sunlight-keyword">function</span> <span class="sunlight-named-ident">main</span> <span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">)</span> <span class="sunlight-punctuation">{</span>
|
||||
  <span class="sunlight-comment">// initialise the provider to connect to the local node</span>
|
||||
  <span class="sunlight-comment">// Initialise the provider to connect to the local node</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-comment">// create the API and wait until ready</span>
|
||||
  <span class="sunlight-comment">// Create the API and wait until ready</span>
|
||||
  <span class="sunlight-reservedWord">const</span> <span class="sunlight-ident">api</span> <span class="sunlight-operator">=</span> <span class="sunlight-ident">await</span> <span class="sunlight-ident">ApiPromise</span><span class="sunlight-operator">.</span><span class="sunlight-ident">create</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-comment">// retrieve the chain & node information information via rpc calls</span>
|
||||
  <span class="sunlight-comment">// Retrieve the chain & node information information via rpc calls</span>
|
||||
  <span class="sunlight-reservedWord">const</span> <span class="sunlight-punctuation">[</span><span class="sunlight-ident">chain</span><span class="sunlight-punctuation">,</span> <span class="sunlight-ident">nodeName</span><span class="sunlight-punctuation">,</span> <span class="sunlight-ident">nodeVersion</span><span class="sunlight-punctuation">]</span> <span class="sunlight-operator">=</span> <span class="sunlight-ident">await</span> <span class="sunlight-ident">Promise</span><span class="sunlight-operator">.</span><span class="sunlight-ident">all</span><span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">[</span>
|
||||
    <span class="sunlight-ident">api</span><span class="sunlight-operator">.</span><span class="sunlight-ident">rpc</span><span class="sunlight-operator">.</span><span class="sunlight-ident">system</span><span class="sunlight-operator">.</span><span class="sunlight-ident">chain</span><span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">,</span>
|
||||
    <span class="sunlight-ident">api</span><span class="sunlight-operator">.</span><span class="sunlight-ident">rpc</span><span class="sunlight-operator">.</span><span class="sunlight-ident">system</span><span class="sunlight-operator">.</span><span class="sunlight-ident">name</span><span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">,</span>
|
||||
@@ -452,7 +452,7 @@
|
||||
<script>
|
||||
var gitbook = gitbook || [];
|
||||
gitbook.push(function() {
|
||||
gitbook.page.hasChanged({"page":{"title":"Simple connect","level":"3.1.1","depth":2,"next":{"title":"Listen to blocks","level":"3.1.2","depth":2,"path":"examples/promise/02_listen_to_blocks/README.md","ref":"examples/promise/02_listen_to_blocks/README.md","articles":[]},"previous":{"title":"ApiPromise","level":"3.1","depth":1,"path":"examples/promise/README.md","ref":"examples/promise/README.md","articles":[{"title":"Simple connect","level":"3.1.1","depth":2,"path":"examples/promise/01_simple_connect/README.md","ref":"examples/promise/01_simple_connect/README.md","articles":[]},{"title":"Listen to blocks","level":"3.1.2","depth":2,"path":"examples/promise/02_listen_to_blocks/README.md","ref":"examples/promise/02_listen_to_blocks/README.md","articles":[]},{"title":"Listen to balance change","level":"3.1.3","depth":2,"path":"examples/promise/03_listen_to_balance_change/README.md","ref":"examples/promise/03_listen_to_balance_change/README.md","articles":[]},{"title":"Read chain state","level":"3.1.4","depth":2,"path":"examples/promise/05_read_storage/README.md","ref":"examples/promise/05_read_storage/README.md","articles":[]},{"title":"Make a transfer","level":"3.1.5","depth":2,"path":"examples/promise/07_transfer_dots/README.md","ref":"examples/promise/07_transfer_dots/README.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":"examples/promise/01_simple_connect/README.md","mtime":"2018-10-12T19:55:00.277Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-10-12T19:58:43.754Z"},"basePath":"../../..","book":{"language":""}});
|
||||
gitbook.page.hasChanged({"page":{"title":"Simple connect","level":"3.1.1","depth":2,"next":{"title":"Listen to blocks","level":"3.1.2","depth":2,"path":"examples/promise/02_listen_to_blocks/README.md","ref":"examples/promise/02_listen_to_blocks/README.md","articles":[]},"previous":{"title":"ApiPromise","level":"3.1","depth":1,"path":"examples/promise/README.md","ref":"examples/promise/README.md","articles":[{"title":"Simple connect","level":"3.1.1","depth":2,"path":"examples/promise/01_simple_connect/README.md","ref":"examples/promise/01_simple_connect/README.md","articles":[]},{"title":"Listen to blocks","level":"3.1.2","depth":2,"path":"examples/promise/02_listen_to_blocks/README.md","ref":"examples/promise/02_listen_to_blocks/README.md","articles":[]},{"title":"Listen to balance change","level":"3.1.3","depth":2,"path":"examples/promise/03_listen_to_balance_change/README.md","ref":"examples/promise/03_listen_to_balance_change/README.md","articles":[]},{"title":"Read chain state","level":"3.1.4","depth":2,"path":"examples/promise/05_read_storage/README.md","ref":"examples/promise/05_read_storage/README.md","articles":[]},{"title":"Make a transfer","level":"3.1.5","depth":2,"path":"examples/promise/07_transfer_dots/README.md","ref":"examples/promise/07_transfer_dots/README.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":"examples/promise/01_simple_connect/README.md","mtime":"2018-10-13T06:57:16.675Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-10-13T07:00:51.958Z"},"basePath":"../../..","book":{"language":""}});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
||||
@@ -388,7 +388,7 @@
|
||||
<p>This example shows how to subscribe to new blocks.</p>
|
||||
<p>It displays the block number every time a new block is seen by the node you are connected to.</p>
|
||||
<p>NOTE: The example runs until you stop it with CTRL+C</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-comment">// API imports</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-comment">// Import the API</span>
|
||||
<span class="sunlight-reservedWord">const</span> <span class="sunlight-punctuation">{</span> <span class="sunlight-ident">ApiPromise</span> <span class="sunlight-punctuation">}</span> <span class="sunlight-operator">=</span> <span class="sunlight-ident">require</span><span class="sunlight-punctuation">(</span><span class="sunlight-string">'@polkadot/api'</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
|
||||
|
||||
<span class="sunlight-ident">async</span> <span class="sunlight-keyword">function</span> <span class="sunlight-named-ident">main</span> <span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">)</span> <span class="sunlight-punctuation">{</span>
|
||||
@@ -400,13 +400,13 @@
|
||||
  <span class="sunlight-comment">// Subscribe to the new headers on-chain. The callback is fired when new headers</span>
|
||||
  <span class="sunlight-comment">// are found, the call itself returns a promise with a subscription that can be</span>
|
||||
  <span class="sunlight-comment">// used to unsubscribe from the newHead subscription</span>
|
||||
  <span class="sunlight-reservedWord">const</span> <span class="sunlight-ident">subsciptionId</span> <span class="sunlight-operator">=</span> <span class="sunlight-ident">await</span> <span class="sunlight-ident">api</span><span class="sunlight-operator">.</span><span class="sunlight-ident">rpc</span><span class="sunlight-operator">.</span><span class="sunlight-ident">chain</span><span class="sunlight-operator">.</span><span class="sunlight-ident">newHead</span><span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">header</span><span class="sunlight-punctuation">)</span> <span class="sunlight-operator">=</span><span class="sunlight-operator">></span> <span class="sunlight-punctuation">{</span>
|
||||
  <span class="sunlight-reservedWord">const</span> <span class="sunlight-ident">subscriptionId</span> <span class="sunlight-operator">=</span> <span class="sunlight-ident">await</span> <span class="sunlight-ident">api</span><span class="sunlight-operator">.</span><span class="sunlight-ident">rpc</span><span class="sunlight-operator">.</span><span class="sunlight-ident">chain</span><span class="sunlight-operator">.</span><span class="sunlight-ident">newHead</span><span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">header</span><span class="sunlight-punctuation">)</span> <span class="sunlight-operator">=</span><span class="sunlight-operator">></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-punctuation">`</span><span class="sunlight-ident">best</span> <span class="sunlight-punctuation">#</span><span class="sunlight-ident">$</span><span class="sunlight-punctuation">{</span><span class="sunlight-ident">header</span><span class="sunlight-operator">.</span><span class="sunlight-ident">blockNumber</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-punctuation">)</span><span class="sunlight-punctuation">;</span>
|
||||
|
||||
  <span class="sunlight-comment">// id for the subscription, we can cleanup and unsubscribe via</span>
|
||||
  <span class="sunlight-comment">// Id for the subscription, we can cleanup and unsubscribe via</span>
|
||||
  <span class="sunlight-comment">// `api.chain.newHead.unsubscribe(subscriptionId)`</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-punctuation">`</span><span class="sunlight-ident">subsciptionId</span><span class="sunlight-operator">:</span> <span class="sunlight-ident">$</span><span class="sunlight-punctuation">{</span><span class="sunlight-ident">subsciptionId</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-punctuation">`</span><span class="sunlight-ident">subsciptionId</span><span class="sunlight-operator">:</span> <span class="sunlight-ident">$</span><span class="sunlight-punctuation">{</span><span class="sunlight-ident">subscriptionId</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">main</span><span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">)</span><span class="sunlight-operator">.</span><span class="sunlight-keyword">catch</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">console</span><span class="sunlight-operator">.</span><span class="sunlight-ident">error</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
|
||||
@@ -454,7 +454,7 @@
|
||||
<script>
|
||||
var gitbook = gitbook || [];
|
||||
gitbook.push(function() {
|
||||
gitbook.page.hasChanged({"page":{"title":"Listen to blocks","level":"3.1.2","depth":2,"next":{"title":"Listen to balance change","level":"3.1.3","depth":2,"path":"examples/promise/03_listen_to_balance_change/README.md","ref":"examples/promise/03_listen_to_balance_change/README.md","articles":[]},"previous":{"title":"Simple connect","level":"3.1.1","depth":2,"path":"examples/promise/01_simple_connect/README.md","ref":"examples/promise/01_simple_connect/README.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":"examples/promise/02_listen_to_blocks/README.md","mtime":"2018-10-12T19:55:00.277Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-10-12T19:58:43.754Z"},"basePath":"../../..","book":{"language":""}});
|
||||
gitbook.page.hasChanged({"page":{"title":"Listen to blocks","level":"3.1.2","depth":2,"next":{"title":"Listen to balance change","level":"3.1.3","depth":2,"path":"examples/promise/03_listen_to_balance_change/README.md","ref":"examples/promise/03_listen_to_balance_change/README.md","articles":[]},"previous":{"title":"Simple connect","level":"3.1.1","depth":2,"path":"examples/promise/01_simple_connect/README.md","ref":"examples/promise/01_simple_connect/README.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":"examples/promise/02_listen_to_blocks/README.md","mtime":"2018-10-13T06:57:16.675Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-10-13T07:00:51.958Z"},"basePath":"../../..","book":{"language":""}});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
||||
@@ -386,30 +386,30 @@
|
||||
|
||||
<h1 id="listen-to-balance-changes">Listen to balance changes</h1>
|
||||
<p>This example shows how to instantiate a Polkadot API object and use it to connect to a node and retrieve balance updates.</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-comment">// import the Api</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-comment">// Import the Api</span>
|
||||
<span class="sunlight-reservedWord">const</span> <span class="sunlight-punctuation">{</span> <span class="sunlight-ident">ApiPromise</span> <span class="sunlight-punctuation">}</span> <span class="sunlight-operator">=</span> <span class="sunlight-ident">require</span><span class="sunlight-punctuation">(</span><span class="sunlight-string">'@polkadot/api'</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
|
||||
|
||||
<span class="sunlight-comment">// the known account we want to use (available on dev chain, with funds)</span>
|
||||
<span class="sunlight-comment">// Known account we want to use (available on dev chain, with funds)</span>
|
||||
<span class="sunlight-reservedWord">const</span> <span class="sunlight-ident">Alice</span> <span class="sunlight-operator">=</span> <span class="sunlight-string">'5GoKvZWG5ZPYL1WUovuHW3zJBWBP5eT8CbqjdRY4Q6iMaDtZ'</span><span class="sunlight-punctuation">;</span>
|
||||
|
||||
<span class="sunlight-ident">async</span> <span class="sunlight-keyword">function</span> <span class="sunlight-named-ident">main</span> <span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">)</span> <span class="sunlight-punctuation">{</span>
|
||||
  <span class="sunlight-comment">// Create an wait for the API</span>
|
||||
  <span class="sunlight-comment">// Create an await for the API</span>
|
||||
  <span class="sunlight-reservedWord">const</span> <span class="sunlight-ident">api</span> <span class="sunlight-operator">=</span> <span class="sunlight-ident">await</span> <span class="sunlight-ident">ApiPromise</span><span class="sunlight-operator">.</span><span class="sunlight-ident">create</span><span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
|
||||
|
||||
  <span class="sunlight-comment">// Retrieve the initial balance. Since the call has no callback, it is simply a promise</span>
|
||||
  <span class="sunlight-comment">// the resolves to the current on-chain value</span>
|
||||
  <span class="sunlight-comment">// that resolves to the current on-chain value</span>
|
||||
  <span class="sunlight-ident">let</span> <span class="sunlight-ident">previous</span> <span class="sunlight-operator">=</span> <span class="sunlight-ident">await</span> <span class="sunlight-ident">api</span><span class="sunlight-operator">.</span><span class="sunlight-ident">query</span><span class="sunlight-operator">.</span><span class="sunlight-ident">balances</span><span class="sunlight-operator">.</span><span class="sunlight-ident">freeBalance</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">Alice</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-punctuation">`</span><span class="sunlight-ident">$</span><span class="sunlight-punctuation">{</span><span class="sunlight-ident">Alice</span><span class="sunlight-punctuation">}</span> <span class="sunlight-ident">has</span> <span class="sunlight-ident">an</span> <span class="sunlight-ident">$</span><span class="sunlight-punctuation">{</span><span class="sunlight-ident">previous</span><span class="sunlight-punctuation">}</span> <span class="sunlight-ident">balance</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-punctuation">`</span><span class="sunlight-ident">$</span><span class="sunlight-punctuation">{</span><span class="sunlight-ident">Alice</span><span class="sunlight-punctuation">}</span> <span class="sunlight-ident">has</span> <span class="sunlight-ident">a</span> <span class="sunlight-ident">$</span><span class="sunlight-punctuation">{</span><span class="sunlight-ident">previous</span><span class="sunlight-punctuation">}</span> <span class="sunlight-ident">balance</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-punctuation">`</span><span class="sunlight-ident">You</span> <span class="sunlight-ident">may</span> <span class="sunlight-ident">leave</span> <span class="sunlight-keyword">this</span> <span class="sunlight-ident">example</span> <span class="sunlight-ident">running</span> <span class="sunlight-ident">and</span> <span class="sunlight-ident">start</span> <span class="sunlight-ident">example</span> <span class="sunlight-number">06</span> <span class="sunlight-ident">or</span> <span class="sunlight-ident">transfer</span> <span class="sunlight-ident">any</span> <span class="sunlight-ident">value</span> <span class="sunlight-ident">to</span> <span class="sunlight-ident">$</span><span class="sunlight-punctuation">{</span><span class="sunlight-ident">Alice</span><span class="sunlight-punctuation">}</span><span class="sunlight-punctuation">`</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
|
||||
|
||||
  <span class="sunlight-comment">// Here we subscribe to any balance changes and updates the on-screen value</span>
|
||||
  <span class="sunlight-comment">// Here we subscribe to any balance changes and update the on-screen value</span>
|
||||
  <span class="sunlight-ident">api</span><span class="sunlight-operator">.</span><span class="sunlight-ident">query</span><span class="sunlight-operator">.</span><span class="sunlight-ident">balances</span><span class="sunlight-operator">.</span><span class="sunlight-ident">freeBalance</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">Alice</span><span class="sunlight-punctuation">,</span> <span class="sunlight-punctuation">(</span><span class="sunlight-ident">current</span><span class="sunlight-punctuation">)</span> <span class="sunlight-operator">=</span><span class="sunlight-operator">></span> <span class="sunlight-punctuation">{</span>
|
||||
    <span class="sunlight-comment">// Calculate the delta</span>
|
||||
    <span class="sunlight-reservedWord">const</span> <span class="sunlight-ident">change</span> <span class="sunlight-operator">=</span> <span class="sunlight-ident">current</span><span class="sunlight-operator">.</span><span class="sunlight-ident">sub</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">previous</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
|
||||
|
||||
    <span class="sunlight-comment">// Only display positive value changes (Since we are pulling previous above already,</span>
|
||||
    <span class="sunlight-comment">// the intiial balance change will also be zero)</span>
|
||||
    <span class="sunlight-comment">// Only display positive value changes (Since we are pulling `previous` above already,</span>
|
||||
    <span class="sunlight-comment">// the initial balance change will also be zero)</span>
|
||||
    <span class="sunlight-keyword">if</span> <span class="sunlight-punctuation">(</span><span class="sunlight-ident">change</span><span class="sunlight-operator">.</span><span class="sunlight-ident">isZero</span><span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">)</span> <span class="sunlight-punctuation">{</span>
|
||||
      <span class="sunlight-keyword">return</span><span class="sunlight-punctuation">;</span>
|
||||
    <span class="sunlight-punctuation">}</span>
|
||||
@@ -465,7 +465,7 @@
|
||||
<script>
|
||||
var gitbook = gitbook || [];
|
||||
gitbook.push(function() {
|
||||
gitbook.page.hasChanged({"page":{"title":"Listen to balance change","level":"3.1.3","depth":2,"next":{"title":"Read chain state","level":"3.1.4","depth":2,"path":"examples/promise/05_read_storage/README.md","ref":"examples/promise/05_read_storage/README.md","articles":[]},"previous":{"title":"Listen to blocks","level":"3.1.2","depth":2,"path":"examples/promise/02_listen_to_blocks/README.md","ref":"examples/promise/02_listen_to_blocks/README.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":"examples/promise/03_listen_to_balance_change/README.md","mtime":"2018-10-12T19:55:00.277Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-10-12T19:58:43.754Z"},"basePath":"../../..","book":{"language":""}});
|
||||
gitbook.page.hasChanged({"page":{"title":"Listen to balance change","level":"3.1.3","depth":2,"next":{"title":"Read chain state","level":"3.1.4","depth":2,"path":"examples/promise/05_read_storage/README.md","ref":"examples/promise/05_read_storage/README.md","articles":[]},"previous":{"title":"Listen to blocks","level":"3.1.2","depth":2,"path":"examples/promise/02_listen_to_blocks/README.md","ref":"examples/promise/02_listen_to_blocks/README.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":"examples/promise/03_listen_to_balance_change/README.md","mtime":"2018-10-13T06:57:16.675Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-10-13T07:00:51.958Z"},"basePath":"../../..","book":{"language":""}});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
||||
@@ -386,14 +386,14 @@
|
||||
|
||||
<h1 id="read-storage">Read storage</h1>
|
||||
<p>Many important variables are available through the storage API. This example shows how to call a few of those APIs.</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-comment">// Import the ApiPromise</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-comment">// Import the API</span>
|
||||
<span class="sunlight-reservedWord">const</span> <span class="sunlight-punctuation">{</span> <span class="sunlight-ident">ApiPromise</span> <span class="sunlight-punctuation">}</span> <span class="sunlight-operator">=</span> <span class="sunlight-ident">require</span><span class="sunlight-punctuation">(</span><span class="sunlight-string">'@polkadot/api'</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
|
||||
|
||||
<span class="sunlight-comment">// Our address for Alice on the dev chain</span>
|
||||
<span class="sunlight-reservedWord">const</span> <span class="sunlight-ident">Alice</span> <span class="sunlight-operator">=</span> <span class="sunlight-string">'5GoKvZWG5ZPYL1WUovuHW3zJBWBP5eT8CbqjdRY4Q6iMaDtZ'</span><span class="sunlight-punctuation">;</span>
|
||||
|
||||
<span class="sunlight-ident">async</span> <span class="sunlight-keyword">function</span> <span class="sunlight-named-ident">main</span> <span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">)</span> <span class="sunlight-punctuation">{</span>
|
||||
  <span class="sunlight-comment">// Create out API with a default connection to the local node</span>
|
||||
  <span class="sunlight-comment">// Create our API with a default connection to the local node</span>
|
||||
  <span class="sunlight-reservedWord">const</span> <span class="sunlight-ident">api</span> <span class="sunlight-operator">=</span> <span class="sunlight-ident">await</span> <span class="sunlight-ident">ApiPromise</span><span class="sunlight-operator">.</span><span class="sunlight-ident">create</span><span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
|
||||
|
||||
  <span class="sunlight-comment">// Make our basic chain state/storage queries, all in one go</span>
|
||||
@@ -406,7 +406,7 @@
|
||||
  <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-punctuation">`</span><span class="sunlight-ident">accountNonce</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">$</span><span class="sunlight-punctuation">{</span><span class="sunlight-ident">Alice</span><span class="sunlight-punctuation">}</span><span class="sunlight-punctuation">)</span> <span class="sunlight-ident">$</span><span class="sunlight-punctuation">{</span><span class="sunlight-ident">accountNonce</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-punctuation">`</span><span class="sunlight-ident">blockPeriod</span> <span class="sunlight-ident">$</span><span class="sunlight-punctuation">{</span><span class="sunlight-ident">blockPeriod</span><span class="sunlight-operator">.</span><span class="sunlight-ident">toNumber</span><span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">}</span> <span class="sunlight-ident">seconds</span><span class="sunlight-punctuation">`</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
|
||||
|
||||
  <span class="sunlight-comment">// get the balances for all validators</span>
|
||||
  <span class="sunlight-comment">// Retrieve the balances for all validators</span>
|
||||
  <span class="sunlight-reservedWord">const</span> <span class="sunlight-ident">validatorBalances</span> <span class="sunlight-operator">=</span> <span class="sunlight-ident">await</span> <span class="sunlight-ident">Promise</span><span class="sunlight-operator">.</span><span class="sunlight-ident">all</span><span class="sunlight-punctuation">(</span>
|
||||
    <span class="sunlight-ident">validators</span><span class="sunlight-operator">.</span><span class="sunlight-ident">map</span><span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">authorityId</span><span class="sunlight-punctuation">)</span> <span class="sunlight-operator">=</span><span class="sunlight-operator">></span>
|
||||
      <span class="sunlight-ident">api</span><span class="sunlight-operator">.</span><span class="sunlight-ident">query</span><span class="sunlight-operator">.</span><span class="sunlight-ident">balances</span><span class="sunlight-operator">.</span><span class="sunlight-ident">freeBalance</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">authorityId</span><span class="sunlight-punctuation">)</span>
|
||||
@@ -464,7 +464,7 @@
|
||||
<script>
|
||||
var gitbook = gitbook || [];
|
||||
gitbook.push(function() {
|
||||
gitbook.page.hasChanged({"page":{"title":"Read chain state","level":"3.1.4","depth":2,"next":{"title":"Make a transfer","level":"3.1.5","depth":2,"path":"examples/promise/07_transfer_dots/README.md","ref":"examples/promise/07_transfer_dots/README.md","articles":[]},"previous":{"title":"Listen to balance change","level":"3.1.3","depth":2,"path":"examples/promise/03_listen_to_balance_change/README.md","ref":"examples/promise/03_listen_to_balance_change/README.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":"examples/promise/05_read_storage/README.md","mtime":"2018-10-12T19:55:00.277Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-10-12T19:58:43.754Z"},"basePath":"../../..","book":{"language":""}});
|
||||
gitbook.page.hasChanged({"page":{"title":"Read chain state","level":"3.1.4","depth":2,"next":{"title":"Make a transfer","level":"3.1.5","depth":2,"path":"examples/promise/07_transfer_dots/README.md","ref":"examples/promise/07_transfer_dots/README.md","articles":[]},"previous":{"title":"Listen to balance change","level":"3.1.3","depth":2,"path":"examples/promise/03_listen_to_balance_change/README.md","ref":"examples/promise/03_listen_to_balance_change/README.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":"examples/promise/05_read_storage/README.md","mtime":"2018-10-13T06:57:16.675Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-10-13T07:00:51.958Z"},"basePath":"../../..","book":{"language":""}});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
||||
@@ -384,7 +384,7 @@
|
||||
|
||||
<h1 id="tranfer-dots">Tranfer DOTs</h1>
|
||||
<p>This sample shows how to create a transaction to make a transfer from one an account to another.</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-comment">// Import our API, Keyring and some utility functions</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-comment">// Import the API, Keyring and some utility functions</span>
|
||||
<span class="sunlight-reservedWord">const</span> <span class="sunlight-punctuation">{</span> <span class="sunlight-ident">ApiPromise</span> <span class="sunlight-punctuation">}</span> <span class="sunlight-operator">=</span> <span class="sunlight-ident">require</span><span class="sunlight-punctuation">(</span><span class="sunlight-string">'@polkadot/api'</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
|
||||
<span class="sunlight-reservedWord">const</span> <span class="sunlight-ident">Keyring</span> <span class="sunlight-operator">=</span> <span class="sunlight-ident">require</span><span class="sunlight-punctuation">(</span><span class="sunlight-string">'@polkadot/keyring'</span><span class="sunlight-punctuation">)</span><span class="sunlight-operator">.</span><span class="sunlight-keyword">default</span><span class="sunlight-punctuation">;</span>
|
||||
<span class="sunlight-reservedWord">const</span> <span class="sunlight-ident">u8aFromUtf8</span> <span class="sunlight-operator">=</span> <span class="sunlight-ident">require</span><span class="sunlight-punctuation">(</span><span class="sunlight-string">'@polkadot/util/u8a/fromUtf8'</span><span class="sunlight-punctuation">)</span><span class="sunlight-operator">.</span><span class="sunlight-keyword">default</span><span class="sunlight-punctuation">;</span>
|
||||
@@ -393,16 +393,16 @@
|
||||
<span class="sunlight-reservedWord">const</span> <span class="sunlight-ident">BOB_ADDR</span> <span class="sunlight-operator">=</span> <span class="sunlight-string">'5Gw3s7q4QLkSWwknsiPtjujPv3XM4Trxi5d4PgKMMk3gfGTE'</span><span class="sunlight-punctuation">;</span>
|
||||
|
||||
<span class="sunlight-ident">async</span> <span class="sunlight-keyword">function</span> <span class="sunlight-named-ident">main</span> <span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">)</span> <span class="sunlight-punctuation">{</span>
|
||||
  <span class="sunlight-comment">// create an instance of the keyring</span>
|
||||
  <span class="sunlight-comment">// Create an instance of the keyring</span>
|
||||
  <span class="sunlight-reservedWord">const</span> <span class="sunlight-ident">keyring</span> <span class="sunlight-operator">=</span> <span class="sunlight-keyword">new</span> <span class="sunlight-ident">Keyring</span><span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
|
||||
|
||||
  <span class="sunlight-comment">// Add Alice to our keyring (with the known seed for the account)</span>
|
||||
  <span class="sunlight-reservedWord">const</span> <span class="sunlight-ident">alice</span> <span class="sunlight-operator">=</span> <span class="sunlight-ident">keyring</span><span class="sunlight-operator">.</span><span class="sunlight-ident">addFromSeed</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">u8aFromUtf8</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">ALICE_SEED</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
|
||||
|
||||
  <span class="sunlight-comment">// instantiate the API</span>
|
||||
  <span class="sunlight-comment">// Instantiate the API</span>
|
||||
  <span class="sunlight-reservedWord">const</span> <span class="sunlight-ident">api</span> <span class="sunlight-operator">=</span> <span class="sunlight-ident">await</span> <span class="sunlight-ident">ApiPromise</span><span class="sunlight-operator">.</span><span class="sunlight-ident">create</span><span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
|
||||
|
||||
  <span class="sunlight-comment">// retrieve the nonce for Alice, used to sign the transaction</span>
|
||||
  <span class="sunlight-comment">// Retrieve the nonce for Alice, to be used to sign the transaction</span>
|
||||
  <span class="sunlight-reservedWord">const</span> <span class="sunlight-ident">aliceNonce</span> <span class="sunlight-operator">=</span> <span class="sunlight-ident">await</span> <span class="sunlight-ident">api</span><span class="sunlight-operator">.</span><span class="sunlight-ident">query</span><span class="sunlight-operator">.</span><span class="sunlight-ident">system</span><span class="sunlight-operator">.</span><span class="sunlight-ident">accountNonce</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">alice</span><span class="sunlight-operator">.</span><span class="sunlight-ident">address</span><span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
|
||||
|
||||
  <span class="sunlight-comment">// Create a extrinsic, transferring 12345 units to Bob. We can also create,</span>
|
||||
@@ -410,10 +410,10 @@
|
||||
  <span class="sunlight-comment">// here we split it out for the sake of readability</span>
|
||||
  <span class="sunlight-reservedWord">const</span> <span class="sunlight-ident">transfer</span> <span class="sunlight-operator">=</span> <span class="sunlight-ident">api</span><span class="sunlight-operator">.</span><span class="sunlight-ident">tx</span><span class="sunlight-operator">.</span><span class="sunlight-ident">balances</span><span class="sunlight-operator">.</span><span class="sunlight-ident">transfer</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">BOB_ADDR</span><span class="sunlight-punctuation">,</span> <span class="sunlight-number">12345</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
|
||||
|
||||
  <span class="sunlight-comment">// sign the transaction using our account</span>
|
||||
  <span class="sunlight-comment">// Sign the transaction using our account</span>
|
||||
  <span class="sunlight-ident">transfer</span><span class="sunlight-operator">.</span><span class="sunlight-ident">sign</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">alice</span><span class="sunlight-punctuation">,</span> <span class="sunlight-ident">aliceNonce</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
|
||||
|
||||
  <span class="sunlight-comment">// send the transaction and retrieve the resulting Hash</span>
|
||||
  <span class="sunlight-comment">// Send the transaction and retrieve the resulting Hash</span>
|
||||
  <span class="sunlight-reservedWord">const</span> <span class="sunlight-ident">hash</span> <span class="sunlight-operator">=</span> <span class="sunlight-ident">await</span> <span class="sunlight-ident">transfer</span><span class="sunlight-operator">.</span><span class="sunlight-ident">send</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-punctuation">`</span><span class="sunlight-ident">transfer</span> <span class="sunlight-number">12345</span> <span class="sunlight-ident">to</span> <span class="sunlight-ident">Bob</span> <span class="sunlight-keyword">with</span> <span class="sunlight-ident">hash</span> <span class="sunlight-ident">$</span><span class="sunlight-punctuation">{</span><span class="sunlight-ident">hash</span><span class="sunlight-punctuation">}</span><span class="sunlight-punctuation">`</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
|
||||
@@ -460,7 +460,7 @@
|
||||
<script>
|
||||
var gitbook = gitbook || [];
|
||||
gitbook.push(function() {
|
||||
gitbook.page.hasChanged({"page":{"title":"Make a transfer","level":"3.1.5","depth":2,"previous":{"title":"Read chain state","level":"3.1.4","depth":2,"path":"examples/promise/05_read_storage/README.md","ref":"examples/promise/05_read_storage/README.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":"examples/promise/07_transfer_dots/README.md","mtime":"2018-10-12T19:55:00.277Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-10-12T19:58:43.754Z"},"basePath":"../../..","book":{"language":""}});
|
||||
gitbook.page.hasChanged({"page":{"title":"Make a transfer","level":"3.1.5","depth":2,"previous":{"title":"Read chain state","level":"3.1.4","depth":2,"path":"examples/promise/05_read_storage/README.md","ref":"examples/promise/05_read_storage/README.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":"examples/promise/07_transfer_dots/README.md","mtime":"2018-10-13T06:57:16.675Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-10-13T07:00:51.958Z"},"basePath":"../../..","book":{"language":""}});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
||||
@@ -442,7 +442,7 @@
|
||||
<script>
|
||||
var gitbook = gitbook || [];
|
||||
gitbook.push(function() {
|
||||
gitbook.page.hasChanged({"page":{"title":"ApiPromise","level":"3.1","depth":1,"next":{"title":"Simple connect","level":"3.1.1","depth":2,"path":"examples/promise/01_simple_connect/README.md","ref":"examples/promise/01_simple_connect/README.md","articles":[]},"previous":{"title":"Extrinsics (runtime)","level":"2.3","depth":1,"path":"METHODS_EXTRINSICS.md","ref":"METHODS_EXTRINSICS.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":"examples/promise/README.md","mtime":"2018-10-12T19:55:00.277Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-10-12T19:58:43.754Z"},"basePath":"../..","book":{"language":""}});
|
||||
gitbook.page.hasChanged({"page":{"title":"ApiPromise","level":"3.1","depth":1,"next":{"title":"Simple connect","level":"3.1.1","depth":2,"path":"examples/promise/01_simple_connect/README.md","ref":"examples/promise/01_simple_connect/README.md","articles":[]},"previous":{"title":"Extrinsics (runtime)","level":"2.3","depth":1,"path":"METHODS_EXTRINSICS.md","ref":"METHODS_EXTRINSICS.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":"examples/promise/README.md","mtime":"2018-10-13T06:57:16.675Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-10-13T07:00:51.958Z"},"basePath":"../..","book":{"language":""}});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user