@cityofzion/neo-js
Version:
Running NEO blockchain full node with Node.js and MongoDB.
317 lines (312 loc) • 17.2 kB
HTML
<html class="default no-js">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>@cityofzion/neo-js</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">@cityofzion/neo-js</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> @cityofzion/neo-js</h1>
</div>
</div>
</header>
<div class="container container-main">
<div class="row">
<div class="col-8 col-content">
<div class="tsd-panel tsd-typography">
<p align="center">
<img
src="http://res.cloudinary.com/vidsy/image/upload/v1503160820/CoZ_Icon_DARKBLUE_200x178px_oq0gxm.png"
width="125px"
alt="City of Zion logo">
</p>
<p align="center" style="font-size: 32px;">
<strong>neo-js</strong>
</p>
<p align="center">
Running NEO blockchain full node with Node.js and MongoDB.
</p>
<p align="center">
<a href="https://badge.fury.io/js/%40cityofzion%2Fneo-js">
<img src="https://badge.fury.io/js/%40cityofzion%2Fneo-js.svg" alt="npm version">
</a>
</p>
<h2 id="overview">Overview</h2>
<p><code>neo-js</code> package is designed to interface with the NEO blockchain in a number of different ways that are configured by options that are used to initialize a node. A few examples of these different interaction mechanics are defined in the quickstart below as well as in the examples.</p>
<p><strong>This is not a SDK library for interacting with NEO blockchain. You are looking for <a href="https://github.com/cityofzion/neon-js"><code>neon-js</code></a>.</strong></p>
<h2 id="getting-started">Getting Started</h2>
<h3 id="preparations">Preparations</h3>
<p>Currently this module only support MongoDB for synchronizing the blockchain. You are expect to be connected to an
instance of MongoDB 3.2+ to use most of its features.</p>
<h3 id="system-recommendations">System Recommendations</h3>
<ul>
<li>NodeJS 8+</li>
<li>MongoDB 3.2+</li>
</ul>
<h2 id="installation">Installation</h2>
<p>Install the package using:</p>
<pre><code class="language-bash">$ npm install --save @cityofzion/neo-js</code></pre>
<p>Alternatively, to access to the latest available code, you can reference to the git repository directly:</p>
<pre><code class="language-bash">$ npm install --save git://github.com/CityOfZion/neo-js.git<span class="hljs-comment">#develop</span></code></pre>
<h2 id="quick-start">Quick Start</h2>
<p>More comprehensive examples can be found at <a href="https://github.com/rockacola/neo-js-examples"><code>neo-js-examples</code></a> repository.</p>
<pre><code class="language-js"><span class="hljs-keyword">const</span> Neo = <span class="hljs-built_in">require</span>(<span class="hljs-string">'@cityofzion/neo-js'</span>).Neo</code></pre>
<p>To create a new blockchain instance:</p>
<pre><code class="language-js"><span class="hljs-comment">// Create a neo instances to interface with RPC methods</span>
<span class="hljs-keyword">const</span> testnetNeo = <span class="hljs-keyword">new</span> Neo({ <span class="hljs-attr">network</span>: <span class="hljs-string">'testnet'</span> })
<span class="hljs-comment">// Wait for mesh to be ready before attempt to fetch block information</span>
testnetNeo.mesh.on(<span class="hljs-string">'ready'</span>, () => {
testnetNeo.api.getBlockCount()
.then(<span class="hljs-function">(<span class="hljs-params">res</span>) =></span> {
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">'Testnet getBlockCount:'</span>, res)
})
})
<span class="hljs-comment">// To connect to the mainnet:</span>
<span class="hljs-keyword">const</span> mainnetNeo = <span class="hljs-keyword">new</span> Neo({ <span class="hljs-attr">network</span>: <span class="hljs-string">'mainnet'</span> })
mainnetNeo.mesh.on(<span class="hljs-string">'ready'</span>, () => {
mainnetNeo.api.getBlock(<span class="hljs-number">1000</span>)
.then(<span class="hljs-function">(<span class="hljs-params">res</span>) =></span> {
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">'Mainnet getBlock(1000).hash:'</span>, res.hash)
})
})</code></pre>
<p>This will create a new node instance and configure it to sync the blockchain to the defined mongoDB collections:</p>
<pre><code class="language-js"><span class="hljs-keyword">const</span> options = {
<span class="hljs-attr">network</span>: <span class="hljs-string">'testnet'</span>,
<span class="hljs-attr">storageType</span>: <span class="hljs-string">'mongodb'</span>,
<span class="hljs-attr">storageOptions</span>: {
<span class="hljs-attr">connectionString</span>: <span class="hljs-string">'mongodb://localhost/neo_testnet'</span>,
},
}
<span class="hljs-comment">// Create a neo instance</span>
<span class="hljs-keyword">const</span> neo = <span class="hljs-keyword">new</span> Neo(options)
<span class="hljs-comment">// Get block height</span>
neo.storage.on(<span class="hljs-string">'ready'</span>, () => {
neo.storage.getHighestBlockHeight()
.then(<span class="hljs-function">(<span class="hljs-params">res</span>) =></span> {
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">'Block height:'</span>, res)
})
})</code></pre>
<h2 id="documentation">Documentation</h2>
<p>Documentation for the project can be found at:</p>
<ul>
<li><a href="http://cityofzion.io/neo-js/">http://cityofzion.io/neo-js/</a></li>
</ul>
<p>You can find more code examples at repository:</p>
<ul>
<li><a href="https://github.com/rockacola/neo-js-examples">https://github.com/rockacola/neo-js-examples</a></li>
</ul>
<h2 id="blockchain-bootstrap-files">Blockchain Bootstrap Files</h2>
<p><a href="https://github.com/CityOfZion/neo-js/blob/master/BOOTSTRAP_FILES.md"><em>Please refer to Bootstrap Files document</em></a></p>
<h2 id="options">Options</h2>
<p><a href="https://github.com/CityOfZion/neo-js/blob/master/OPTIONAL_PARAMETERS.md"><em>Please refer to Optional Parameters document</em></a></p>
<h2 id="events">Events</h2>
<p><a href="https://github.com/CityOfZion/neo-js/blob/master/EVENT_EMITTERS.md"><em>Please refer to Event Emitters document</em></a></p>
<h2 id="contribution">Contribution</h2>
<p><code>neo-js</code> always encourages community code contribution. Before contributing please read the <a href="https://github.com/CityOfZion/neo-js/blob/master/.github/CONTRIBUTING.md">contributor guidelines</a> and search the issue tracker as your issue may have already been discussed or fixed. To contribute, fork <code>neo-js</code>, commit your changes and submit a pull request.</p>
<p>By contributing to <code>neo-js</code>, you agree that your contributions will be licensed under its MIT license.</p>
<h2 id="license">License</h2>
<ul>
<li>Open-source <a href="https://github.com/CityOfZion/neo-js/blob/master/LICENSE.md">MIT</a>.</li>
<li>Authors:<ul>
<li><a href="https://github.com/lllwvlvwlll">@lllwvlvwlll</a></li>
<li><a href="https://github.com/rockacola">@rockacola</a></li>
</ul>
</li>
</ul>
</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/_analyzers_block_analyzer_.html">"analyzers/block-<wbr>analyzer"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_common_constants_.html">"common/constants"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_common_profiles_.html">"common/profiles"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_core_api_.html">"core/api"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_core_mesh_.html">"core/mesh"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_core_node_.html">"core/node"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_core_syncer_.html">"core/syncer"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_delegates_rpc_delegate_.html">"delegates/rpc-<wbr>delegate"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_helpers_block_helper_.html">"helpers/block-<wbr>helper"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_neo_.html">"neo"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_storages_memory_storage_.html">"storages/memory-<wbr>storage"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_storages_mongodb_storage_.html">"storages/mongodb-<wbr>storage"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_storages_mongodb_block_dao_.html">"storages/mongodb/block-<wbr>dao"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_storages_mongodb_block_meta_dao_.html">"storages/mongodb/block-<wbr>meta-<wbr>dao"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_storages_mongodb_schemas_.html">"storages/mongodb/schemas"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_storages_mongodb_transaction_meta_dao_.html">"storages/mongodb/transaction-<wbr>meta-<wbr>dao"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_storages_mongodb_utils_.html">"storages/mongodb/utils"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_validators_endpoint_validator_.html">"validators/endpoint-<wbr>validator"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_validators_mongodb_validator_.html">"validators/mongodb-<wbr>validator"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_validators_neo_validator_.html">"validators/neo-<wbr>validator"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_validators_rpc_validator_.html">"validators/rpc-<wbr>validator"</a>
</li>
</ul>
</nav>
<nav class="tsd-navigation secondary menu-sticky">
<ul class="before-current">
</ul>
</nav>
</div>
</div>
</div>
<footer class="with-border-bottom">
<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="container tsd-generator">
<p>Generated using <a href="http://typedoc.org/" target="_blank">TypeDoc</a></p>
</div>
<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>