1.0.0 • Published 4 years ago

bubichain-js-query v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
4 years ago

bubichain-js-query

A simple query module for the BU chain.

js-standard-style

Install

$ npm install --save bubichain-js-query

Test

The tests can be run with Node.js

$ npm test

Usage

Create bubichain-js-query instance

const Query = require('bubichain-js-query')
const query = new Query({
  host: 'http://node.bubidev.cn',
  timeout: 1000 * 60
})

Get account info

const address = 'buQrH4ab27ZCD4WCxGJtmPpFQ5SubFg6t3bj'
const accountInfo = await query.getAccountInfo(address)
console.log(accountInfo)

// result:
// {
//   address: 'buQrH4ab27ZCD4WCxGJtmPpFQ5SubFg6t3bj',
//   balance: '100000000000000000',
//   nonce: '0',
//   assets: [],
//   priv: {
//    master_weight: '1',
//    thresholds: {
//     tx_threshold: '1'
//    }
//   }
// }

Get account metadata

const address = 'buQrH4ab27ZCD4WCxGJtmPpFQ5SubFg6t3bj'
const key = 'test'
const metadata = await query.getMetadata(address, key)
console.log(metadata)

// result:
// {
//   key: 'test',
//   value: 'value',
//   version: 1.0
// }

Get account balance

const address = 'buQrH4ab27ZCD4WCxGJtmPpFQ5SubFg6t3bj'
const balance = await query.getBalance(address)
console.log(balance)

// result:
// "100000000000000000"

Get account nonce

const address = 'buQrH4ab27ZCD4WCxGJtmPpFQ5SubFg6t3bj'
const nonce = await query.getNonce(address)
console.log(nonce)

// result:
// "0"

Get block info

const blockNumber = '100'
const blockInfo = await query.getBlockInfo(blockNumber)
console.log(blockInfo)

// result:
// {
//  closeTime: '1567997123667055',
//  number: '100',
//  txCount: '',
//  version: '1003' 
// }

Get get latest info

const blockInfo = await query.getLatestInfo()
console.log(blockInfo)

// result:
// {
//  closeTime: '1567997123667055',
//  number: '100',
//  txCount: '',
//  version: '1003' 
// }

Get validators for specific blockNumber

const blockNumber = '100'
const validators = await query.getValidators(blockNumber)
console.log(validators)

// result:
// [ 'buQBwe7LZYCYHfxiEGb1RE9XC9kN2qrGXWCY' ]

Get latest validators

const validators = await query.getLatestValidators()
console.log(validators)

// result:
// [ 'buQBwe7LZYCYHfxiEGb1RE9XC9kN2qrGXWCY' ]

Send transaction

const signedTransactionInfo = {
  items: [{
    transaction_blob: blob,
    signatures: signatures
  }]
}

const hash = await query.sendTransaction(signedTransactionInfo)
console.log(hash)

// result:
// '8bb1d61daac2ac2f7726fe5114d0d3747eedbb0e3764d046b8976f8d614982bb'
1.0.0

4 years ago