The BurstCoin Type/Javascript Reference Library
@burstjs is a modern library written in Typescript providing common functionalities for browsers and nodejs to interact with the BurstCoin blockchain,
an advanced community-driven blockchain technology.
The library is separated in the following packages
@burstjs aims modern browsers and nodejs > v10, but can also be used as bundled JavaScript using <script>
Install using npm:
npm install @burstjs/core
npm install @burstjs/contracts (optional)
npm install @burstjs/crypto (optional)
npm install @burstjs/util (optional)
npm install @burstjs/http (optional)or using yarn:
yarn add @burstjs/core
yarn add @burstjs/contracts (optional)
yarn add @burstjs/crypto (optional)
yarn add @burstjs/util (optional)
yarn add @burstjs/http (optional)
Usually, you won't need to install other packages than
@burstjs/core, which uses the other packages.
<script>Each package is available as bundled standalone library using IIFE.
This way burstJS can be used also within <script>-Tags.
This might be useful for Wordpress and/or other PHP applications.
Just import one of the packages using the HTML <script> tag.
<script src='https://cdn.jsdelivr.net/npm/@burstjs/core/dist/burstjs.min.js'></script>
<script src='https://cdn.jsdelivr.net/npm/@burstjs/contracts/dist/burstjs.contracts.min.js'></script>
<script src='https://cdn.jsdelivr.net/npm/@burstjs/crypto/dist/burstjs.crypto.min.js'></script>
<script src='https://cdn.jsdelivr.net/npm/@burstjs/http/dist/burstjs.http.min.js'></script>
<script src='https://cdn.jsdelivr.net/npm/@burstjs/util/dist/burstjs.util.min.js'></script>
Due to the way a package is imported following global variables are provided
| Package | Variable |
|---|---|
| core | b$ |
| crypto | b$contracts |
| crypto | b$crypto |
| http | b$http |
| util | b$util |
Examples:
// using core
const api = b$.composeApi({
nodeHost: "http://at-testnet.burst-alliance.org:6876",
apiRootUrl: "/burst"
});
api.network.getBlockchainStatus().then(console.log);
// using contracts
const dataView = new b$contracts.ContractDataView(contract)
console.log(dataView.getVariable(2))
// 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)
The following example shows how to interact with the blockchain, i.e. getting the balance of a specific account
In a separate file, preferribly index.js or main.js write your entry point like this:
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}`)
}
})()
<script> styleconst apiSettings = new b$.ApiSettings('http://at-testnet.burst-alliance.org:6876', 'burst');
const api = b$.composeApi(apiSettings);
api.account.getAccountBalance('13036514135565182944')
.then( balance => {
console.log(`Account Balance: ${b$util.convertNQTStringToNumber(balance.balanceNQT)} BURST`)
})
.catch(e => { // e is of type HttpError (as part of @burstjs/http)
console.error(`Whooops, something went wrong: ${e.message}`)
})