5 ### [Keys](https://bytom.github.io/node-sdk/global.html#Key__anchor)
7 Cryptographic keys are the primary authorization mechanism on a blockchain.
9 To create accounts or assets, xpub of keys are required. With this sdk, we can
10 `create/delete/list/resetPassword` the key. Please check the
11 [API doc](https://bytom.github.io/node-sdk/module-KeysApi.html) if you want
14 ### [Account](https://bytom.github.io/node-sdk/global.html#Account__anchor)
16 An account is an object in Bytom that tracks ownership of assets on a blockchain.
17 It's defined under one Bytom node created with one or serveral keys.
19 [Related API](https://bytom.github.io/node-sdk/module-AccountsApi.html)
21 ### [Asset](https://bytom.github.io/node-sdk/global.html#Asset__anchor)
23 An asset is a type of value that can be issued on a blockchain. All units of
24 a given asset are fungible. Units of an asset can be transacted directly
25 between parties without the involvement of the issuer.
27 [Related API](https://bytom.github.io/node-sdk/module-AssetsApi.html)
29 ### [Transaction](https://bytom.github.io/node-sdk/global.html#Transaction__anchor)
31 Blockchain is chain of blocks, while block consists of numbers of transactions.
33 [Related API](https://bytom.github.io/node-sdk/module-TransactionsApi.html)
35 ### [Unspent Output(UTXO)](https://bytom.github.io/node-sdk/global.html#UnspentOutput__anchor)
37 Bytom is UTXO based blockchain. One transaction spend some UTXOs, and produces new UTXOs.
39 [Related API](https://bytom.github.io/node-sdk/module-UnspentOutputsApi.html)
41 ### [Balance](https://bytom.github.io/node-sdk/global.html#Balance__anchor)
43 Any balance on the blockchain is simply a summation of UTXOs. In one bytomd, balance means
44 summation of UTXOs of one account.
46 [Related API](https://bytom.github.io/node-sdk/module-BalancesApi.html)
53 const bytom = require('bytom-sdk')
54 const url = 'http://localhost:9888'
56 // access token is required when client is not in same origin
57 // with the request bytom node
58 const accessToken = ''
60 const client = new bytom.Client(url, accessToken)
63 ## Interaction with bytom
65 We will walk you through the process to issue some assets.
67 ### Step 1: create a key
70 const keyPromise = client.keys.create('alias', 'password')
73 It will create a key whose alias is 'alias' while password is 'password'.
75 ### Step 2: create a account
78 const accountPromise = keyPromise.then(key => {
79 client.accounts.create([key.xpub], 1, 'account')
83 ### Step 3: create account address
86 const addressPromise = accountPromise.then(account => {
87 return client.accounts.createReceiverById(account.id)
91 ### Step 4: create asset
100 const assetPromise = keyPromise.then(key => {
101 return client.assets.create([key.xpub], 1, 'asset', definition)
105 ### Step 5: issue asset
107 #### First, build the transaction
110 const buildPromise = Promise.all([
114 ).then(([account, address, asset]) => {
115 const issueAction = {
117 asset_alias: asset.alias,
122 type: 'spend_account',
123 account_alias: account.alias,
128 const controlAction = {
129 type: 'control_address',
131 asset_alias: asset.alias,
132 address: address.address
135 return client.transactions.build(null,
136 [issueAction, gasAction, controlAction])
141 #### Second, sign the transaction
144 const signPromise = buildPromise.then(transactionTemplate => {
145 return client.transactions.sign(transactionTemplate, 'password')
149 #### Finally, submit the signed transaction to the bytom network
152 signPromise.then(signed => {
153 return client.transactions.submit(signed.transaction.raw_transaction)