Node.js SDK for Bytom protocol
名前 | サイズ | Rev. | 日時 | 作者 | ログメッセージ |
---|---|---|---|---|---|
docs | |||||
src | |||||
test | |||||
.babelrc | 28 | 528001a | 2018-05-11 11:11:54 | Yongfeng LI | configure babel |
.gitignore | 48 | 68a3d79 | 2018-11-26 18:05:03 | Zhiting Lin | update gitignore |
.npmignore | 9 | c93a4c1 | 2018-05-22 11:06:56 | Yongfeng LI | prepare for publish |
README.md | 5 k | 2a12f6a | 2018-11-26 18:02:52 | Zhiting Lin | update the document |
jsdoc.conf.json | 337 | 8d1d600 | 2018-05-21 14:06:23 | Yongfeng LI | add docs |
package-lock.json | 82.2 k | 44970ea | 2018-11-26 18:26:44 | Zhiting Lin | update mocha and growl |
package.json | 849 | 5f85570 | 2018-11-26 19:02:19 | Zhiting Lin | update to v1.0.2 |
yarn.lock | 56.13 k | ceef919 | 2018-05-11 15:13:15 | Yongfeng LI | add jsdoc |
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.
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.
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.
Blockchain is chain of blocks, while block consists of numbers of transactions.
Bytom is UTXO based blockchain. One transaction spend some UTXOs, and produces new UTXOs.
Any balance on the blockchain is simply a summation of UTXOs. In one bytomd, balance means summation of UTXOs of one account.
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.
Config contain the network information that you wanted to know.
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)
We will walk you through the process to issue some assets.
const keyPromise = client.keys.create({
alias:'key',
password: 'password'
})
It will create a key whose alias is 'alias' while password is 'password'.
const accountPromise = keyPromise.then(key => {
client.accounts.create({
alias: 'account',
root_xpubs: [key.xpub],
quorum: 1
})
})
const addressPromise = accountPromise.then(account => {
return client.accounts.createReceiver({
account_alias: account.alias
})
})
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
})
})
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)
})
})
const signPromise = buildPromise.then(transactionTemplate => {
return client.transactions.sign({
transaction: transactionTemplate,
password: 'password'
})
})
signPromise.then(signed => {
return client.transactions.submit(signed.transaction.raw_transaction)
})