UNPKG

@ellcrys/spell

Version:

The official JavaScript library for Ellcrys

253 lines (250 loc) 13 kB
<!doctype html> <html class="default no-js"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>Spell Documentation</title> <meta name="description" content=""> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="assets/css/main.css"> </head> <body> <header> <div class="tsd-page-toolbar"> <div class="container"> <div class="table-wrap"> <div class="table-cell" id="tsd-search" data-index="assets/js/search.js" data-base="."> <div class="field"> <label for="tsd-search-field" class="tsd-widget search no-caption">Search</label> <input id="tsd-search-field" type="text" /> </div> <ul class="results"> <li class="state loading">Preparing search index...</li> <li class="state failure">The search index is not available</li> </ul> <a href="index.html" class="title">Spell Documentation</a> </div> <div class="table-cell" id="tsd-widgets"> <div id="tsd-filter"> <a href="#" class="tsd-widget options no-caption" data-toggle="options">Options</a> <div class="tsd-filter-group"> <div class="tsd-select" id="tsd-filter-visibility"> <span class="tsd-select-label">All</span> <ul class="tsd-select-list"> <li data-value="public">Public</li> <li data-value="protected">Public/Protected</li> <li data-value="private" class="selected">All</li> </ul> </div> <input type="checkbox" id="tsd-filter-inherited" checked /> <label class="tsd-widget" for="tsd-filter-inherited">Inherited</label> <input type="checkbox" id="tsd-filter-externals" checked /> <label class="tsd-widget" for="tsd-filter-externals">Externals</label> <input type="checkbox" id="tsd-filter-only-exported" /> <label class="tsd-widget" for="tsd-filter-only-exported">Only exported</label> </div> </div> <a href="#" class="tsd-widget menu no-caption" data-toggle="menu">Menu</a> </div> </div> </div> </div> <div class="tsd-page-title"> <div class="container"> <ul class="tsd-breadcrumb"> <li> <a href="globals.html">Globals</a> </li> </ul> <h1> Spell Documentation</h1> </div> </div> </header> <div class="container container-main"> <div class="row"> <div class="col-8 col-content"> <div class="tsd-panel tsd-typography"> <h1 id="spell">Spell</h1> <p>The official Node.js binding for the Elld JSON-RPC 2.0 Service! This library provides the ability to query or mutate the state and configuration an Ellcrys blockchain client.</p> <h2 id="installation">Installation</h2> <pre><code><span class="hljs-built_in">npm</span> install @ellcrys/spell</code></pre><h2 id="initialization">Initialization</h2> <p>To begin using the client, you must first create a Spell instance and provide connection information that will enable the client connect to the JSON-RPC 2.0 service.</p> <pre><code class="language-js"><span class="hljs-comment">// Create a Spell Instance</span> <span class="hljs-keyword">const</span> spell = <span class="hljs-keyword">new</span> Spell(); <span class="hljs-comment">// Configure the client to be able</span> <span class="hljs-comment">// to make calls to a node's RPC service</span> spell.provideClient({ <span class="hljs-comment">// The RPC address of an Elld node</span> host: <span class="hljs-string">"127.0.0.1"</span>, <span class="hljs-comment">// The RPC port of an Elld node</span> port: <span class="hljs-number">8999</span>, <span class="hljs-comment">// Optional: RPC username to access private endpoints</span> username: <span class="hljs-string">"admin"</span>, <span class="hljs-comment">// Optional: RPC password to access private endpoints</span> password: <span class="hljs-string">"secret"</span>, });</code></pre> <p><code>provideClient</code> will attempt to call <code>rpc_echo</code> to test the connection; It will return a rejected promise if it failed to successfully reach the node.</p> <h2 id="calling-an-rpc-method">Calling An RPC Method</h2> <p>Spell closely replicates the same namespace-based structure used to organize the RPC methods in Elld. For example, RPC methods on Elld are named and addressed in the following format:</p> <pre><code><span class="hljs-comment">{namespace}</span>_<span class="hljs-comment">{method}</span> <span class="hljs-keyword">Where</span>: - <span class="hljs-keyword">namespace</span>: The <span class="hljs-keyword">group</span> name a <span class="hljs-function"><span class="hljs-keyword">method</span> <span class="hljs-title">belongs</span> <span class="hljs-title">to</span> - <span class="hljs-title">method</span>:</span> <span class="hljs-keyword">Is</span> the name <span class="hljs-keyword">of</span> the <span class="hljs-function"><span class="hljs-keyword">method</span>.</span></code></pre><p>All supported namespaces can be accessed from the spell instance like this:</p> <pre><code class="language-js">spell.namespace.method();</code></pre> <h2 id="get-a-node-s-basic-information">Get A Node&#39;s Basic Information</h2> <p>We will demonstrate how to call an RPC method by getting the basic information of the provisioned node.</p> <pre><code class="language-js"><span class="hljs-comment">// Get a node's basic information. The JSON-RPC 2.0 method is</span> <span class="hljs-comment">// `node_basic`</span> spell.node.basic(); <span class="hljs-comment">// Output:</span> <span class="hljs-comment">/* { buildCommit: '599bc716098869a0d2a15431447c65823c207e3f', buildDate: '2019-01-19T21:57:50Z', buildVersion: '0.1.6-alpha.2', goVersion: 'go1.10.4', id: '12D3KooWKAEhd4DXGPeN71FeSC1ih86Ym2izpoPueaCrME8xu8UM', mode: 'production', name: 'deeply-suitable-fowl', netVersion: '0001', syncing: false, tipBlockDifficulty: '0x215915d', tipBlockHash: '0x1cf3109273187d2c42ad077fc7b491eae8a4fd1878ef9ec74f0d12d4843a9168', tipBlockHeight: '0x45d9', tipBlockTotalDifficulty: '0xb60329599c' } */</span></code></pre> <h2 id="documentation">Documentation</h2> <p>See API Reference <a href="https://ellcrys.github.io/spell">here</a></p> </div> </div> <div class="col-4 col-menu menu-sticky-wrap menu-highlight"> <nav class="tsd-navigation primary"> <ul> <li class="globals "> <a href="globals.html"><em>Globals</em></a> </li> <li class=" tsd-kind-external-module"> <a href="modules/auth.html">Auth</a> </li> <li class=" tsd-kind-external-module"> <a href="modules/ell.html">Ell</a> </li> <li class=" tsd-kind-external-module"> <a href="modules/errors.html">Errors</a> </li> <li class=" tsd-kind-external-module"> <a href="modules/index.html">Index</a> </li> <li class=" tsd-kind-external-module"> <a href="modules/key.html">Key</a> </li> <li class=" tsd-kind-external-module"> <a href="modules/logger.html">Logger</a> </li> <li class=" tsd-kind-external-module"> <a href="modules/miner.html">Miner</a> </li> <li class=" tsd-kind-external-module"> <a href="modules/namespace.html">Namespace</a> </li> <li class=" tsd-kind-external-module"> <a href="modules/net.html">Net</a> </li> <li class=" tsd-kind-external-module"> <a href="modules/node.html">Node</a> </li> <li class=" tsd-kind-external-module"> <a href="modules/pool.html">Pool</a> </li> <li class=" tsd-kind-external-module"> <a href="modules/rpc.html">RPC</a> </li> <li class=" tsd-kind-external-module"> <a href="modules/rpcclient.html">RPCClient</a> </li> <li class=" tsd-kind-external-module"> <a href="modules/spell.html">Spell</a> </li> <li class=" tsd-kind-external-module"> <a href="modules/state.html">State</a> </li> <li class=" tsd-kind-external-module"> <a href="modules/transactionbuilder.html">Transaction<wbr>Builder</a> </li> <li class=" tsd-kind-external-module"> <a href="modules/txutility.html">Tx<wbr>Utility</a> </li> </ul> </nav> <nav class="tsd-navigation secondary menu-sticky"> <ul class="before-current"> </ul> </nav> </div> </div> </div> <footer> <div class="container"> <h2>Legend</h2> <div class="tsd-legend-group"> <ul class="tsd-legend"> <li class="tsd-kind-module"><span class="tsd-kind-icon">Module</span></li> <li class="tsd-kind-object-literal"><span class="tsd-kind-icon">Object literal</span></li> <li class="tsd-kind-variable"><span class="tsd-kind-icon">Variable</span></li> <li class="tsd-kind-function"><span class="tsd-kind-icon">Function</span></li> <li class="tsd-kind-function tsd-has-type-parameter"><span class="tsd-kind-icon">Function with type parameter</span></li> <li class="tsd-kind-index-signature"><span class="tsd-kind-icon">Index signature</span></li> <li class="tsd-kind-type-alias"><span class="tsd-kind-icon">Type alias</span></li> </ul> <ul class="tsd-legend"> <li class="tsd-kind-enum"><span class="tsd-kind-icon">Enumeration</span></li> <li class="tsd-kind-enum-member"><span class="tsd-kind-icon">Enumeration member</span></li> <li class="tsd-kind-property tsd-parent-kind-enum"><span class="tsd-kind-icon">Property</span></li> <li class="tsd-kind-method tsd-parent-kind-enum"><span class="tsd-kind-icon">Method</span></li> </ul> <ul class="tsd-legend"> <li class="tsd-kind-interface"><span class="tsd-kind-icon">Interface</span></li> <li class="tsd-kind-interface tsd-has-type-parameter"><span class="tsd-kind-icon">Interface with type parameter</span></li> <li class="tsd-kind-constructor tsd-parent-kind-interface"><span class="tsd-kind-icon">Constructor</span></li> <li class="tsd-kind-property tsd-parent-kind-interface"><span class="tsd-kind-icon">Property</span></li> <li class="tsd-kind-method tsd-parent-kind-interface"><span class="tsd-kind-icon">Method</span></li> <li class="tsd-kind-index-signature tsd-parent-kind-interface"><span class="tsd-kind-icon">Index signature</span></li> </ul> <ul class="tsd-legend"> <li class="tsd-kind-class"><span class="tsd-kind-icon">Class</span></li> <li class="tsd-kind-class tsd-has-type-parameter"><span class="tsd-kind-icon">Class with type parameter</span></li> <li class="tsd-kind-constructor tsd-parent-kind-class"><span class="tsd-kind-icon">Constructor</span></li> <li class="tsd-kind-property tsd-parent-kind-class"><span class="tsd-kind-icon">Property</span></li> <li class="tsd-kind-method tsd-parent-kind-class"><span class="tsd-kind-icon">Method</span></li> <li class="tsd-kind-accessor tsd-parent-kind-class"><span class="tsd-kind-icon">Accessor</span></li> <li class="tsd-kind-index-signature tsd-parent-kind-class"><span class="tsd-kind-icon">Index signature</span></li> </ul> <ul class="tsd-legend"> <li class="tsd-kind-constructor tsd-parent-kind-class tsd-is-inherited"><span class="tsd-kind-icon">Inherited constructor</span></li> <li class="tsd-kind-property tsd-parent-kind-class tsd-is-inherited"><span class="tsd-kind-icon">Inherited property</span></li> <li class="tsd-kind-method tsd-parent-kind-class tsd-is-inherited"><span class="tsd-kind-icon">Inherited method</span></li> <li class="tsd-kind-accessor tsd-parent-kind-class tsd-is-inherited"><span class="tsd-kind-icon">Inherited accessor</span></li> </ul> <ul class="tsd-legend"> <li class="tsd-kind-property tsd-parent-kind-class tsd-is-protected"><span class="tsd-kind-icon">Protected property</span></li> <li class="tsd-kind-method tsd-parent-kind-class tsd-is-protected"><span class="tsd-kind-icon">Protected method</span></li> <li class="tsd-kind-accessor tsd-parent-kind-class tsd-is-protected"><span class="tsd-kind-icon">Protected accessor</span></li> </ul> <ul class="tsd-legend"> <li class="tsd-kind-property tsd-parent-kind-class tsd-is-private"><span class="tsd-kind-icon">Private property</span></li> <li class="tsd-kind-method tsd-parent-kind-class tsd-is-private"><span class="tsd-kind-icon">Private method</span></li> <li class="tsd-kind-accessor tsd-parent-kind-class tsd-is-private"><span class="tsd-kind-icon">Private accessor</span></li> </ul> <ul class="tsd-legend"> <li class="tsd-kind-property tsd-parent-kind-class tsd-is-static"><span class="tsd-kind-icon">Static property</span></li> <li class="tsd-kind-call-signature tsd-parent-kind-class tsd-is-static"><span class="tsd-kind-icon">Static method</span></li> </ul> </div> </div> </footer> <div class="overlay"></div> <script src="assets/js/main.js"></script> <script>if (location.protocol == 'file:') document.write('<script src="assets/js/search.js"><' + '/script>');</script> </body> </html>