• R/O
  • HTTP
  • SSH
  • HTTPS

bytom-node-sdk: Zusammenfassung des Repository

Node.js SDK for Bytom protocol


Neueste Commits RSS

Rev. Zeit Autor Nachricht
5f85570 2018-11-26 19:02:19 Zhiting Lin master v1.0.2 update to v1.0.2
44970ea 2018-11-26 18:26:44 Zhiting Lin update mocha and growl
4ba7ee8 2018-11-26 18:22:40 Zhiting Lin update test case
dc887b0 2018-11-26 18:14:12 Zhiting Lin Merge pull request #3 from Bytom/dev Dev
eb64d4c 2018-11-26 18:12:59 Zhiting Lin merge master into dev
68a3d79 2018-11-26 18:05:03 Zhiting Lin update gitignore
fb6c097 2018-11-26 18:04:47 Zhiting Lin update API
2a12f6a 2018-11-26 18:02:52 Zhiting Lin update the document
a860068 2018-11-23 18:07:53 Zhiting Lin update doc-link
71af33e 2018-11-23 17:36:27 Zhiting Lin add the test case for node-sdk

Kürzlich bearbeitete Tags

Name Rev. Zeit Autor
v1.0.2 5f85570 2018-11-26 19:02:19 Zhiting Lin
v1.0.1 99362f6 2018-05-23 12:17:14 Yongfeng LI

Zweige

Name Rev. Zeit Autor Nachricht
master 5f85570 2018-11-26 19:02:19 Zhiting Lin update to v1.0.2

README.md

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/listAll/resetPassword/checkPassword the key. Please check the 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. It's defined under one Bytom node created with one or serveral keys.

Related API

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.

Related API

Transaction

Blockchain is chain of blocks, while block consists of numbers of transactions.

Related API

Unspent Output(UTXO)

Bytom is UTXO based blockchain. One transaction spend some UTXOs, and produces new UTXOs.

Related API

Balance

Any balance on the blockchain is simply a summation of UTXOs. In one bytomd, balance means summation of UTXOs of one account.

Related API

Block

​ 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.

Related API

Config

Config contain the network information that you wanted to know.

Related API

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
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:'key', 
          password: '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({
     alias: 'account', 
     root_xpubs: [key.xpub], 
     quorum: 1 
 })
})

Step 3: create account address

const addressPromise = accountPromise.then(account => {
  return client.accounts.createReceiver({
    account_alias: account.alias
  })
})

Step 4: create asset

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
    })
})

Step 5: issue asset

First, build the transaction

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)
  })
})

Second, sign the transaction

const signPromise = buildPromise.then(transactionTemplate => {
  return client.transactions.sign({
    transaction: transactionTemplate, 
    password: 'password'
  })
})

Finally, submit the signed transaction to the bytom network

signPromise.then(signed => {
  return client.transactions.submit(signed.transaction.raw_transaction)
})
Show on old repository browser