Skip to content

Library Initialization

Aleksei Lebedev edited this page Sep 29, 2019 · 13 revisions

You can install API JS library using npm or add it to project's dependencies. See Readme for reference.

To use library in Node.js project, initialize it, passing passPhrase of ADAMANT account, list of ADAMANT nodes and log object:

// file api.js
const log = require('../helpers/log');
const config = require('./configReader');
module.exports = require('adamant-api')({passPhrase: config.passPhrase, node: config.node_ADM}, log);

Then refer to JS API:

// file checkerTransactions.js
const api = require('./api');
...

const txChat = (await api.get('uri', 'chats/get/?recipientId=' + Store.user.ADM.address + '&orderBy=timestamp:desc&fromHeight=' + (Store.lastHeight - 5))).transactions;

List of ADAMANT nodes is an array including nodes you want to connect. The library does Health Check — pings all the nodes in the list using status endpoint, and connect to node which alive and with actual height. See an example of ADAMANT nodes list.

Log object is used to log current operations. You must implement error, info, warn an log methods. See an example.

Clone this wiki locally