如何使用BURSTJS获得BURST帐户余额?

时间:2019-10-28 18:08:34

标签: javascript java reactjs typescript react-native

以下软件包中的模块功能如何获得BURST帐户余额? https://burstappsteam.org/phoenix/ https://www.npmjs.com/search?q=burstjs 此后只有几句话,还想解释更多细节。

1 个答案:

答案 0 :(得分:0)

在不做任何尝试的情况下,我仍然会使用您自己发布的链接来回答您的问题。

连接到区块链:

// using core
const api = b$.composeApi({
  nodeHost: "http://at-testnet.burst-alliance.org:6876",
  apiRootUrl: "/burst"
});

api.network.getBlockchainStatus().then(console.log);
// using crypto
console.log(b$crypto.hashSHA256("test"))
// using util
const value = b$util.convertNumberToNQTString(1000)
// using http
const client = new b$http.HttpImpl('https://jsonplaceholder.typicode.com/');
client.get('/todos/1').then(console.log)

然后在一个单独的文件中(“最好是index.js或main.js这样写入口点:”)

import {composeApi, ApiSettings} from '@burstjs/core'
import {convertNQTStringToNumber} from '@burstjs/util'

const apiSettings = new ApiSettings('http://at-testnet.burst-alliance.org:6876', 'burst');
const api = composeApi(apiSettings);

// this self-executing file makes turns this file into a starting point of your app

(async () => {
  try{
    const {balanceNQT} = await api.account.getAccountBalance('13036514135565182944')
    console.log(`Account Balance: ${convertNQTStringToNumber(balanceNQT)} BURST`)  
  }
  catch(e){ // e is of type HttpError (as part of @burstjs/http)
    console.error(`Whooops, something went wrong: ${e.message}`)      
  }
})()

如果这不能满足您的答案,请检查文档页面。