SignumJS
  • ๐Ÿ‘‹Welcome to SignumJS
  • Getting Started
    • Installation
    • Modules
    • Usage
  • ๐Ÿ‘ฉโ€๐Ÿ’ปReference
    • API Reference
      • Core Module
      • Util Module
      • Crypto Module
      • Http Module
      • Contracts Module
      • Monitor Module
  • ๐ŸงพRecipes
    • Basics
      • Getting Accounts Balance
      • List Transactions
      • Show attached messages
      • Send Signa
    • Advanced
Powered by GitBook
On this page
  1. Getting Started

Usage

PreviousModulesNextAPI Reference

Last updated 3 years ago

Once you have added SignumJS to your application you usually want to connect to one of the Signum Network nodes to interact with the blockchain.

All you need is to create an API instance to get access to the methods of the blockchain API.

The following example shows how to get an account from the chain.

index.js
const {composeApi} = require('@signumjs/core');

(async () => {
    const api = composeApi({
        nodeHost: 'https://europe.signum.network',
    });

    const account = await api.account.getAccount({accountId: '16107620026796983538'});
    console.log('Account', account);
})();

index.ts
import {composeApi} from '@signumjs/core';

(async (): Promise<void> => {
    const api = composeApi({
        nodeHost: 'https://europe.signum.network',
    });

    const account = await api.account.getAccount({accountId: '16107620026796983538'});
    console.log('Account', account);
})();

It is essential to understand the concept of and in Javascript. Many functions of SignumJS require to communicate with remote servers and therefore you need to be familiar with asynchronous Javascript.

Usage with bundles

When using the bundles imported via , you need to use the respective namespace to get access to the any of the functions within a module.

index.html
<html lang="en">
<head>
    <link rel="stylesheet" href="css/styles.css">
    <!-- Importing the bundles from the CDN -->
    <script type="application/javascript"
            src='https://cdn.jsdelivr.net/npm/@signumjs/core/dist/signumjs.min.js'></script>
</head>
<body>
    <!-- your body -->
    <script type="application/ecmascript" src="src/main.js"></script>
</body>
main.js
(async () => {
    // the 'namespace' of @signum/core is sig$
    const api = sig$.composeApi({
        nodeHost: 'https://europe.signum.network',
    });

    const account = await api.account.getAccount({accountId: '16107620026796983538'});
    console.log('Account', account);
})();

Each module of SignumJS comes with its own namespace

Module
Namespace
Example

core

sig$

contracts

sig$contracts

crypto

sig$crypto

http

sig$http

monitor

sig$monitor

util

sig$util

The modules are bundled using , to avoid global naming collisions with your application. Keep also in mind, that the bundles do not contain any type information, so your IDE cannot help you with auto-completion.

const api = sig$.composeApi({
        nodeHost: 'https://europe.signum.network',
    });
const dataView = new sig$contracts.ContractDataView(contract)
const hash = sig$crypto.hashSHA256("test")
const client = new sig$http.HttpClientFactory.createHttpClient('https://jsonplaceholder.typicode.com/');
const monitor = new sig$monitor.Monitor<Account>({
    asyncFetcherFn: tryFetchAccount,
    compareFn: checkIfAccountExists,
    intervalSecs: 10, 
        key: 'monitor-account',
    timeoutSecs: 2 * 240 
})
const value = sig$util.Amount.fromSigna("1000")
IIFE
async/await
Promises
<script/>