zetrix-js-query
v1.1.1
Published
A simple query module for the Zetrix chain.
Downloads
38
Readme
zetrix-js-query
A simple query module for the Zetrix.
Install
$ npm install --save zetrix-js-query
Test
The tests can be run with Node.js
$ npm test
Usage
Create zetrix-js-query instance
const Query = require('zetrix-js-query')
const query = new Query({
host: 'http://node.zetrix.com',
timeout: 1000 * 60
})
Get account info
const address = 'ZTX3eDic98F4nzwanvx2f1F3deJZzx3jJNzsN'
const accountInfo = await query.getAccountInfo(address)
console.log(accountInfo)
Get account metadata
const address = 'ZTX3eDic98F4nzwanvx2f1F3deJZzx3jJNzsN'
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 = 'ZTX3eDic98F4nzwanvx2f1F3deJZzx3jJNzsN'
const balance = await query.getBalance(address)
console.log(balance)
// result:
// "100000000000000000"
Get account nonce
const address = 'ZTX3eDic98F4nzwanvx2f1F3deJZzx3jJNzsN'
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)
Get latest validators
const validators = await query.getLatestValidators()
console.log(validators)
Send transaction
const signedTransactionInfo = {
items: [{
transaction_blob: blob,
signatures: signatures
}]
}
const hash = await query.sendTransaction(signedTransactionInfo)
console.log(hash)
// result:
// '8bb1d61daac2ac2f7726fe5114d0d3747eedbb0e3764d046b8976f8d614982bb'