In this simple example we just get an accounts balance and print it to the console.
In the basic examples we still show how to use SignumJS depending the way you are using SignumJS, i.e. imported via NodeJS package manager or as minified bundle. In case you haven't read about the module system, take a quick look there:
Address Value Object to parse and convert the given address
Amount Value Object to convert between Planck and Signa
const {Address,composeApi} =require("@signumjs/core")const {Amount} =require("@signumjs/util")// Create the Api instance to connect to a blockchain nodeconstapi=composeApi({ nodeHost:"https://europe.signum.network"});asyncfunctiongetBalance(account) {// All API calls are asynchronous// The recommended pattern is using async/await// This makes exception handling easy using try/catchtry {// We just create an address instance of incoming account string, which// might be the numeric id or an address like 'S-ABCD....'// It throws an error, if the input is not a valid address or account idconstaddress=Address.create(account)// Now, we call the getAccountBalance methodconst {balanceNQT} =awaitapi.account.getAccountBalance(address.getNumericId());// all amounts coming from the blockchain are expressed in Planck // 1 SIGNA = 100000000 Planck// so we need to convert them using the Amount Value Object classconstbalance=Amount.fromPlanck(balanceNQT)// Print it to the consoleconsole.info(`Balance of ${address.getReedSolomonAddress()} is:`,balance.toString()) } catch (e) {console.error(e.message) }}
import {Address, composeApi} from"@signumjs/core"import {Amount} from"@signumjs/util"// Create the Api instance to connect to a blockchain nodeconstapi=composeApi({ nodeHost:"https://europe.signum.network"});asyncfunctiongetBalance(account:string) :Promise<void> {// All API calls are asynchronous// The recommended pattern is using async/await// This makes exception handling easy using try/catchtry {// We just create an address instance of incoming account string, which// might be the numeric id or an address like 'S-ABCD....'// It throws an error, if the input is not a valid address or account idconstaddress=Address.create(account)// Now, we call the getAccountBalance methodconst {balanceNQT} =awaitapi.account.getAccountBalance(address.getNumericId());// all amounts coming from the blockchain are expressed in Planck // 1 SIGNA = 100000000 Planck// so we need to convert them using the Amount Value Object classconstbalance=Amount.fromPlanck(balanceNQT)// Print it to the consoleconsole.info(`Balance of ${address.getReedSolomonAddress()} is:`,balance.toString()) } catch (e) {console.error(e.message) }}
// you need to have imported in your index.html:/*<script src='https://cdn.jsdelivr.net/npm/@signumjs/core/dist/signumjs.min.js'></script><script src='https://cdn.jsdelivr.net/npm/@signumjs/util/dist/signumjs.util.min.js'></script>*/// Create the Api instance to connect to a blockchain nodeconstapi=sig$.composeApi({ nodeHost:"https://europe.signum.network"});asyncfunctiongetBalance(account) {// All API calls are asynchronous// The recommended pattern is using async/await// This makes exception handling easy using try/catchtry {// We just create an address instance of incoming account string, which// might be the numeric id or an address like 'S-ABCD....'// It throws an error, if the input is not a valid address or account idconstaddress=sig$.Address.create(account)// Now, we call the getAccountBalance methodconst {balanceNQT} =awaitapi.account.getAccountBalance(address.getNumericId());// all amounts coming from the blockchain are expressed in Planck // 1 SIGNA = 100000000 Planck// so we need to convert them using the Amount Value Object classconstbalance=sig$util.Amount.fromPlanck(balanceNQT)// Print it to the consoleconsole.info(`Balance of ${address.getReedSolomonAddress()} is:`,balance.toString()) } catch (e) {console.error(e.message) }}