mirror of
https://github.com/Bytom/bytom-node-sdk.git
synced 2020-06-03 17:14:54 +00:00
337 lines
12 KiB
HTML
337 lines
12 KiB
HTML
<!DOCTYPE html>
|
||
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta name="viewport" content="width=device-width">
|
||
<title>Bytom Node.js SDK Index</title>
|
||
|
||
<!--[if lt IE 9]>
|
||
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
||
<![endif]-->
|
||
<link type="text/css" rel="stylesheet" href="styles/sunlight.default.css">
|
||
|
||
<link type="text/css" rel="stylesheet" href="styles/site.cosmo.css">
|
||
|
||
</head>
|
||
|
||
<body>
|
||
|
||
<div class="navbar navbar-default navbar-fixed-top ">
|
||
<div class="container">
|
||
<div class="navbar-header">
|
||
<a class="navbar-brand" href="index.html">Bytom Node.js SDK</a>
|
||
<button class="navbar-toggle" type="button" data-toggle="collapse" data-target="#topNavigation">
|
||
<span class="icon-bar"></span>
|
||
<span class="icon-bar"></span>
|
||
<span class="icon-bar"></span>
|
||
</button>
|
||
</div>
|
||
<div class="navbar-collapse collapse" id="topNavigation">
|
||
<ul class="nav navbar-nav">
|
||
|
||
<li class="dropdown">
|
||
<a href="modules.list.html" class="dropdown-toggle" data-toggle="dropdown">Modules<b class="caret"></b></a>
|
||
<ul class="dropdown-menu ">
|
||
<li><a href="module-AccessTokensApi.html">AccessTokensApi</a></li><li><a href="module-AccountsApi.html">AccountsApi</a></li><li><a href="module-AssetsApi.html">AssetsApi</a></li><li><a href="module-BalancesApi.html">BalancesApi</a></li><li><a href="module-BlockAPI.html">BlockAPI</a></li><li><a href="module-ConfigApi.html">ConfigApi</a></li><li><a href="module-KeysApi.html">KeysApi</a></li><li><a href="module-TransactionsApi.html">TransactionsApi</a></li><li><a href="module-UnspentOutputsApi.html">UnspentOutputsApi</a></li>
|
||
</ul>
|
||
</li>
|
||
|
||
<li class="dropdown">
|
||
<a href="classes.list.html" class="dropdown-toggle" data-toggle="dropdown">Classes<b class="caret"></b></a>
|
||
<ul class="dropdown-menu ">
|
||
<li><a href="TransactionBuilder.html">TransactionBuilder</a></li>
|
||
</ul>
|
||
</li>
|
||
|
||
<li class="dropdown">
|
||
<a href="global.html" class="dropdown-toggle" data-toggle="dropdown">Global<b class="caret"></b></a>
|
||
<ul class="dropdown-menu ">
|
||
<li><a href="global.html">Global</a></li>
|
||
</ul>
|
||
</li>
|
||
|
||
</ul>
|
||
|
||
<div class="col-sm-3 col-md-3">
|
||
<form class="navbar-form" role="search">
|
||
<div class="input-group">
|
||
<input type="text" class="form-control" placeholder="Search" name="q" id="search-input">
|
||
<div class="input-group-btn">
|
||
<button class="btn btn-default" id="search-submit"><i class="glyphicon glyphicon-search"></i></button>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
</div>
|
||
|
||
</div>
|
||
|
||
</div>
|
||
</div>
|
||
|
||
|
||
<div class="container" id="toc-content">
|
||
<div class="row">
|
||
|
||
|
||
<div class="col-md-8">
|
||
|
||
<div id="main">
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<section class="readme-section">
|
||
<article><h1>Bytom Node.js SDK</h1><h2>Terminology</h2><h3><a href="https://bytom.github.io/bytom-node-sdk/global.html#Key__anchor">Keys</a></h3><p>Cryptographic keys are the primary authorization mechanism on a blockchain.</p>
|
||
<p>To create accounts or assets, xpub of keys are required. With this sdk, we can
|
||
<code>create/delete/listAll/resetPassword/checkPassword</code> the key. Please check the
|
||
<a href="https://bytom.github.io/bytom-node-sdk/module-KeysApi.html">API doc</a> if you want
|
||
to operate with keys.</p>
|
||
<h3><a href="https://bytom.github.io/bytom-node-sdk/global.html#Account__anchor">Account</a></h3><p>An account is an object in Bytom that tracks ownership of assets on a blockchain.
|
||
It's defined under one Bytom node created with one or serveral keys. </p>
|
||
<p><a href="https://bytom.github.io/bytom-node-sdk/module-AccountsApi.html">Related API</a></p>
|
||
<h3><a href="https://bytom.github.io/bytom-node-sdk/global.html#Asset__anchor">Asset</a></h3><p>An asset is a type of value that can be issued on a blockchain. All units of
|
||
a given asset are fungible. Units of an asset can be transacted directly
|
||
between parties without the involvement of the issuer.</p>
|
||
<p><a href="https://bytom.github.io/bytom-node-sdk/module-AssetsApi.html">Related API</a></p>
|
||
<h3><a href="https://bytom.github.io/bytom-node-sdk/global.html#Transaction__anchor">Transaction</a></h3><p>Blockchain is chain of blocks, while block consists of numbers of transactions.</p>
|
||
<p><a href="https://bytom.github.io/bytom-node-sdk/module-TransactionsApi.html">Related API</a></p>
|
||
<h3><a href="https://bytom.github.io/bytom-node-sdk/global.html#UnspentOutput__anchor">Unspent Output(UTXO)</a></h3><p>Bytom is UTXO based blockchain. One transaction spend some UTXOs, and produces new UTXOs.</p>
|
||
<p><a href="https://bytom.github.io/bytom-node-sdk/module-UnspentOutputsApi.html">Related API</a></p>
|
||
<h3><a href="https://bytom.github.io/bytom-node-sdk/global.html#Balance__anchor">Balance</a></h3><p>Any balance on the blockchain is simply a summation of UTXOs. In one bytomd, balance means
|
||
summation of UTXOs of one account.</p>
|
||
<p><a href="https://bytom.github.io/bytom-node-sdk/module-BalancesApi.html">Related API</a></p>
|
||
<h3><a href="https://bytom.github.io/bytom-node-sdk/global.html#Block__anchor">Block</a></h3><p> A block is a container data structure that aggregates transactions for inclusion in the public ledger, the blockchain.
|
||
It is made of a header, containing metadata, followed by a long list of transactions that make up the bulk of its size.
|
||
Each block references to the previous block, and all the blocks are linked from the back to the front to grow a blockchain.</p>
|
||
<p><a href="https://bytom.github.io/bytom-node-sdk/module-BlockApi.html">Related API</a></p>
|
||
<h3><a href="https://bytom.github.io/bytom-node-sdk/global.html#Config__anchor">Config</a></h3><p>Config contain the network information that you wanted to know. </p>
|
||
<p><a href="https://bytom.github.io/bytom-node-sdk/module-ConfigApi.html">Related API</a></p>
|
||
<h2>Usage</h2><h3>In your code</h3><pre class="prettyprint source lang-javascript"><code>const bytom = require('bytom-sdk')
|
||
const url = 'http://localhost:9888'
|
||
|
||
// access token is required when client is not in same origin
|
||
// with the request bytom node
|
||
const accessToken = ''
|
||
|
||
const client = new bytom.Client(url, accessToken)</code></pre><h2>Interaction with bytom</h2><p>We will walk you through the process to issue some assets.</p>
|
||
<h3>Step 1: create a key</h3><pre class="prettyprint source lang-javascript"><code>const keyPromise = client.keys.create({
|
||
alias:'key',
|
||
password: 'password'
|
||
})</code></pre><p>It will create a key whose alias is 'alias' while password is 'password'.</p>
|
||
<h3>Step 2: create a account</h3><pre class="prettyprint source lang-javascript"><code>const accountPromise = keyPromise.then(key => {
|
||
client.accounts.create({
|
||
alias: 'account',
|
||
root_xpubs: [key.xpub],
|
||
quorum: 1
|
||
})
|
||
})</code></pre><h3>Step 3: create account address</h3><pre class="prettyprint source lang-javascript"><code>const addressPromise = accountPromise.then(account => {
|
||
return client.accounts.createReceiver({
|
||
account_alias: account.alias
|
||
})
|
||
})</code></pre><h3>Step 4: create asset</h3><pre class="prettyprint source lang-javascript"><code>const definition = {
|
||
name: "GOLD",
|
||
symbol: "GOLD",
|
||
decimals: 8,
|
||
description: {}
|
||
}
|
||
|
||
const assetPromise = keyPromise.then(key => {
|
||
return client.assets.create(
|
||
{
|
||
alias: 'asset',
|
||
definition,
|
||
root_xpubs: [key.xpub],
|
||
quorum: 1
|
||
})
|
||
})</code></pre><h3>Step 5: issue asset</h3><h4>First, build the transaction</h4><pre class="prettyprint source lang-javascript"><code>const buildPromise = Promise.all([
|
||
accountPromise,
|
||
addressPromise,
|
||
assetPromise]
|
||
).then(([account, address, asset]) => {
|
||
const issueAction = {
|
||
amount: 100000000,
|
||
asset_alias: asset.alias,
|
||
}
|
||
|
||
const gasAction = {
|
||
account_alias: account.alias,
|
||
asset_alias: 'BTM',
|
||
amount: 50000000
|
||
}
|
||
|
||
const controlAction = {
|
||
amount: 100000000,
|
||
asset_alias: asset.alias,
|
||
address: address.address
|
||
}
|
||
|
||
return client.transactions.build(builder => {
|
||
builder.issue(issueAction)
|
||
builder.spendFromAccount(gasAction)
|
||
builder.controlWithAddress(controlAction)
|
||
})
|
||
})
|
||
</code></pre><h4>Second, sign the transaction</h4><pre class="prettyprint source lang-javascript"><code>const signPromise = buildPromise.then(transactionTemplate => {
|
||
return client.transactions.sign({
|
||
transaction: transactionTemplate,
|
||
password: 'password'
|
||
})
|
||
})</code></pre><h4>Finally, submit the signed transaction to the bytom network</h4><pre class="prettyprint source lang-javascript"><code>signPromise.then(signed => {
|
||
return client.transactions.submit(signed.transaction.raw_transaction)
|
||
})</code></pre></article>
|
||
</section>
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
</div>
|
||
</div>
|
||
|
||
<div class="clearfix"></div>
|
||
|
||
|
||
<div class="col-md-3">
|
||
<div id="toc" class="col-md-3 hidden-xs hidden-sm hidden-md"></div>
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
|
||
|
||
<div class="modal fade" id="searchResults">
|
||
<div class="modal-dialog">
|
||
<div class="modal-content">
|
||
<div class="modal-header">
|
||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||
<h4 class="modal-title">Search results</h4>
|
||
</div>
|
||
<div class="modal-body"></div>
|
||
<div class="modal-footer">
|
||
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
|
||
</div>
|
||
</div><!-- /.modal-content -->
|
||
</div><!-- /.modal-dialog -->
|
||
</div>
|
||
|
||
|
||
<footer>
|
||
|
||
|
||
<span class="jsdoc-message">
|
||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>
|
||
|
||
on 2018-11-26T16:28:32+08:00
|
||
|
||
using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
|
||
</span>
|
||
</footer>
|
||
|
||
<script src="scripts/docstrap.lib.js"></script>
|
||
<script src="scripts/toc.js"></script>
|
||
|
||
<script type="text/javascript" src="scripts/fulltext-search-ui.js"></script>
|
||
|
||
|
||
<script>
|
||
$( function () {
|
||
$( "[id*='$']" ).each( function () {
|
||
var $this = $( this );
|
||
|
||
$this.attr( "id", $this.attr( "id" ).replace( "$", "__" ) );
|
||
} );
|
||
|
||
$( ".tutorial-section pre, .readme-section pre, pre.prettyprint.source" ).each( function () {
|
||
var $this = $( this );
|
||
|
||
var example = $this.find( "code" );
|
||
exampleText = example.html();
|
||
var lang = /{@lang (.*?)}/.exec( exampleText );
|
||
if ( lang && lang[1] ) {
|
||
exampleText = exampleText.replace( lang[0], "" );
|
||
example.html( exampleText );
|
||
lang = lang[1];
|
||
} else {
|
||
var langClassMatch = example.parent()[0].className.match(/lang\-(\S+)/);
|
||
lang = langClassMatch ? langClassMatch[1] : "javascript";
|
||
}
|
||
|
||
if ( lang ) {
|
||
|
||
$this
|
||
.addClass( "sunlight-highlight-" + lang )
|
||
.addClass( "linenums" )
|
||
.html( example.html() );
|
||
|
||
}
|
||
} );
|
||
|
||
Sunlight.highlightAll( {
|
||
lineNumbers : true,
|
||
showMenu : true,
|
||
enableDoclinks : true
|
||
} );
|
||
|
||
$.catchAnchorLinks( {
|
||
navbarOffset: 10
|
||
} );
|
||
$( "#toc" ).toc( {
|
||
anchorName : function ( i, heading, prefix ) {
|
||
return $( heading ).attr( "id" ) || ( prefix + i );
|
||
},
|
||
selectors : "#toc-content h1,#toc-content h2,#toc-content h3,#toc-content h4",
|
||
showAndHide : false,
|
||
smoothScrolling: true
|
||
} );
|
||
|
||
$( "#main span[id^='toc']" ).addClass( "toc-shim" );
|
||
$( '.dropdown-toggle' ).dropdown();
|
||
|
||
$( "table" ).each( function () {
|
||
var $this = $( this );
|
||
$this.addClass('table');
|
||
} );
|
||
|
||
} );
|
||
</script>
|
||
|
||
|
||
|
||
<!--Navigation and Symbol Display-->
|
||
|
||
|
||
<!--Google Analytics-->
|
||
|
||
|
||
|
||
<script type="text/javascript">
|
||
$(document).ready(function() {
|
||
SearcherDisplay.init();
|
||
});
|
||
</script>
|
||
|
||
|
||
</body>
|
||
</html> |