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 api doc if you want
15 An account is an object in Bytom that tracks ownership of assets on a blockchain.
16 It's defined under one Bytom node created with one or serveral keys.
20 An asset is a type of value that can be issued on a blockchain. All units of
21 a given asset are fungible. Units of an asset can be transacted directly
22 between parties without the involvement of the issuer.
26 Blockchain is chain of blocks, while block consists of numbers of transactions.
28 ### Unspent Output(UTXO)
30 Bytom is UTXO based blockchain. One transaction spend some UTXOs, and produces new UTXOs.
34 Any balance on the blockchain is simply a summation of UTXOs. In one bytomd, balance means
35 summation of UTXOs of one account.
42 const bytom = require('bytom-sdk')
43 const url = 'http://localhost:9888'
45 const client = new bytom.Client(url)
48 ## Interaction with bytom
50 We will walk you through the process to issue some assets.
52 ### Step 1: create a key
55 const keyPromise = client.keys.create('alias', 'password')
58 It will create a key whose alias is 'alias' while password is 'password'.
60 ### Step 2: create a account
63 const accountPromise = keyPromise.then(key => client.accounts.create([key.xpub], 1, 'account'))
66 ### Step 3: create account address
68 const addressPromise = accountPromise.then(account => {
69 return client.accounts.createReceiverById(account.id)
72 ### Step 4: create asset
75 const definition = {name: "GOLD", symobol: "GOLD", decimals: 8, description: {}}
76 const assetPromise = keyPromise.then(key => {
77 return client.assets.create([key.xpub], 1, 'asset', definition)
81 ### Step 5: issue asset
83 #### First, build the transaction
86 const buildPromise = Promise.all([accountPromise, addressPromise, assetPromise]).then(([account, address, asset]) => {
89 asset_alias: asset.alias,
94 type: 'spend_account',
95 account_alias: account.alias,
100 const controlAction = {
101 type: 'control_address',
103 asset_alias: asset.alias,
104 address: address.address
107 return client.transactions.build(null, [issueAction, gasAction, controlAction])
112 #### Second, sign the transaction
115 const signPromise = buildPromise.then(transactionTemplate => {
116 return client.transactions.sign(transactionTemplate, 'password')
120 #### Finally, submit the signed transaction to the bytom network
123 signPromise.then(signed => {
124 return client.transactions.submit(signed.transaction.raw_transaction)