Bytom Node.js SDK
Terminology
Keys
Cryptographic keys are the primary authorization mechanism on a blockchain.
+Bytom Node.js SDK
Terminology
Keys
Cryptographic keys are the primary authorization mechanism on a blockchain.
To create accounts or assets, xpub of keys are required. With this sdk, we can
create/delete/list/resetPassword
the key. Please check the
-API doc if you want
+API doc if you want
to operate with keys.
Account
An account is an object in Bytom that tracks ownership of assets on a blockchain. +
Account
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.
- -Asset
An asset is a type of value that can be issued on a blockchain. All units of +
+Asset
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.
- -Transaction
Blockchain is chain of blocks, while block consists of numbers of transactions.
- -Unspent Output(UTXO)
Bytom is UTXO based blockchain. One transaction spend some UTXOs, and produces new UTXOs.
- -Balance
Any balance on the blockchain is simply a summation of UTXOs. In one bytomd, balance means +
+Transaction
Blockchain is chain of blocks, while block consists of numbers of transactions.
+ +Unspent Output(UTXO)
Bytom is UTXO based blockchain. One transaction spend some UTXOs, and produces new UTXOs.
+ +Balance
Any balance on the blockchain is simply a summation of UTXOs. In one bytomd, balance means summation of UTXOs of one account.
- -Usage
In your code
const bytom = require('bytom-sdk')
+
+Usage
In your 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
+// 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)
Interaction with bytom
We will walk you through the process to issue some assets.
Step 1: create a key
const keyPromise = client.keys.create('alias', 'password')
It will create a key whose alias is 'alias' while password is 'password'.
-Step 2: create a account
const accountPromise = keyPromise.then(key => client.accounts.create([key.xpub], 1, 'account'))
Step 3: create account address
const addressPromise = accountPromise.then(account => {
+
Step 2: create a account
const accountPromise = keyPromise.then(key => {
+ client.accounts.create([key.xpub], 1, 'account')
+})
Step 3: create account address
const addressPromise = accountPromise.then(account => {
return client.accounts.createReceiverById(account.id)
-})
-Step 4: create asset
const definition = {name: "GOLD", symobol: "GOLD", decimals: 8, description: {}}
+})
Step 4: create asset
const definition = {
+ name: "GOLD",
+ symobol: "GOLD",
+ decimals: 8,
+ description: {}
+}
const assetPromise = keyPromise.then(key => {
return client.assets.create([key.xpub], 1, 'asset', definition)
-})
Step 5: issue asset
First, build the transaction
const buildPromise = Promise.all([accountPromise, addressPromise, assetPromise]).then(([account, address, asset]) => {
+})
Step 5: issue asset
First, build the transaction
const buildPromise = Promise.all([
+ accountPromise,
+ addressPromise,
+ assetPromise]
+ ).then(([account, address, asset]) => {
const issueAction = {
amount: 10000000000,
asset_alias: asset.alias,
@@ -147,7 +158,8 @@ const assetPromise = keyPromise.then(key => {
address: address.address
}
- return client.transactions.build(null, [issueAction, gasAction, controlAction])
+ return client.transactions.build(null,
+ [issueAction, gasAction, controlAction])
})
Second, sign the transaction
const signPromise = buildPromise.then(transactionTemplate => {
return client.transactions.sign(transactionTemplate, 'password')
@@ -199,7 +211,7 @@ const assetPromise = keyPromise.then(key => {
diff --git a/docs/module-AccessTokensApi.html b/docs/module-AccessTokensApi.html
index 29f5bec..58e9c8a 100644
--- a/docs/module-AccessTokensApi.html
+++ b/docs/module-AccessTokensApi.html
@@ -578,7 +578,7 @@
diff --git a/docs/module-AccountsApi.html b/docs/module-AccountsApi.html
index 41d05fa..489565c 100644
--- a/docs/module-AccountsApi.html
+++ b/docs/module-AccountsApi.html
@@ -1562,7 +1562,7 @@
diff --git a/docs/module-AssetsApi.html b/docs/module-AssetsApi.html
index 1b14912..5ace80b 100644
--- a/docs/module-AssetsApi.html
+++ b/docs/module-AssetsApi.html
@@ -1185,7 +1185,7 @@
diff --git a/docs/module-BalancesApi.html b/docs/module-BalancesApi.html
index 8220637..97b4bd1 100644
--- a/docs/module-BalancesApi.html
+++ b/docs/module-BalancesApi.html
@@ -298,7 +298,7 @@
diff --git a/docs/module-KeysApi.html b/docs/module-KeysApi.html
index df09837..e74dfb2 100644
--- a/docs/module-KeysApi.html
+++ b/docs/module-KeysApi.html
@@ -798,7 +798,7 @@
diff --git a/docs/module-TransactionsApi.html b/docs/module-TransactionsApi.html
index d7ea84b..e65a763 100644
--- a/docs/module-TransactionsApi.html
+++ b/docs/module-TransactionsApi.html
@@ -1690,7 +1690,7 @@ Asset info(either asset_id or asset_alias ) is required for all kinds of action.
diff --git a/docs/module-UnspentOutputsApi.html b/docs/module-UnspentOutputsApi.html
index 7b3fe69..719ab7a 100644
--- a/docs/module-UnspentOutputsApi.html
+++ b/docs/module-UnspentOutputsApi.html
@@ -450,7 +450,7 @@
diff --git a/docs/modules.list.html b/docs/modules.list.html
index cf01d6d..ce90ecd 100644
--- a/docs/modules.list.html
+++ b/docs/modules.list.html
@@ -195,7 +195,7 @@
diff --git a/docs/quicksearch.html b/docs/quicksearch.html
index 43dafac..050b7e5 100644
--- a/docs/quicksearch.html
+++ b/docs/quicksearch.html
@@ -7,7 +7,7 @@