Skip to content

API Specification

Royalynx edited this page Sep 16, 2019 · 31 revisions

Get information by synchronous request

To collect information from ADAMANT blockchain you need to use get.js module.

Mode: synchronous

Module format

api.get(type, input):

  • type — consists of endpoint or full url
  • input — consists of filters and options (if available for endpont)

Type variants:

Type Url Response type Response
account /api/accounts?address= + [input] list List\ of accounts filtered by input
account_delegates /api/accounts/delegates?address= + [input] field Named delegates list of delegates account votes for
block /api/blocks/get?id= + [input] list Full information of block with id = input
blocks /api/blocks + [input] field Named blocks list of blocks filtered by input
!!!!! state /api/states/get?id= + [input] list List of transacions type = 9 with asset type state
delegate /api/delegates/get?username= + [input] field Named delegate block information of delegate with username = [input]
delegate_voters /api/delegates/voters?publicKey= + [input] field ! Named accounts list of voters of delegate with publicKey = [input]
delegate_forged /api/delegates/forging/getForgedByAccount?generatorPublicKey= + [input] string Forging activity of delegate with publicKey = [input]
!!!!! transaction /api/transactions/get?id= + [input] !!!!! list Transaction with id = [input]
transactions /api/transactions? + [input] list List of transactions filtered by input
uri /api/ + [input] -

Code examples:

  1. const txChat = (await api.get(`uri`, `chats/get/?recipientId=` + Store.user.ADM.address + `&orderBy=timestamp:desc&fromHeight=` + (Store.lastHeight - 5))).transactions;
  2. const txTrx = (await api.get(`transactions`, `fromHeight=` + (Store.lastHeight - 5) + `&and:recipientId=` + Store.user.ADM.address + `&and:type=0`)).transactions;
  3. const lastBlock = (await api.get(`uri`, `blocks`)).blocks[0];

Get information by asynchronous request

To get information from ADAMANT blockchain without maintaining the connection you need to use syncGet.js module.

Mode: asynchronous

Module format

api.syncGet(uri, isUrl, isNoJson):

  • uri — endpoint or full url; mandatory
  • isUrl — boolen (true/false (default)); optional. In fales case you will get url as: currentNode + uri; At true case url = uri
  • isNoJson — boolen (true/false (default)); optional. In true case JSON body would be parsed

Code examples:

  1. const data = await api.syncGet(config.infoservice + `/get`, true);
  2. const resp = await api.syncGet(`/api/states/get?senderId=${admAddress}&key=${coin.toLowerCase()}:address`);

Send information

To send information to ADAMANT blockchain you need to use send.js module.

Mode: synchronous

Module format

api.send(passPhrase, address, payload, type = 'tokens', isEncode, amount_comment):

  • passPhrase — sender's passPhrase; mandatory
  • address — resipient's ADAMANT address; mandatory
  • payload — sending value; optional
  • type — type of payload: tokens (default) or message; optional
  • isEncode — mark that payment is encoded; optional
  • amount_comment — comment of payment; optional

Code examples:

  1. const result = await $u[outCurrency].send({ address: senderKvsOutAddress, value: outAmount, comment: `Hey, you are lucky! Waiting for new bets!` // if ADM }); log.info(`Reward payment result: ${JSON.stringify(result, 0, 2)}.`); const { address, value, comment } = params; console.log(`Send ${value} ADM to ${address} with comment:`, comment); let res; if (comment){ res = api.send(User.passPhrase, address, comment, `message`, null, value); } else { res = api.send(User.passPhrase, address, value, null, comment); } console.log(`Send result:`, res); if (!res) { return { success: false }; } return { success: res.success, hash: res.transactionId };

  2. sendAdmMsg(address, msg, type = `message`) { if (msg && !config.isDev || true) { try { let msg_markdown = msg.replace(/[^\*]\*[^\*]/g, `**`); return api.send(config.passPhrase, address, msg_markdown, type).success || false; } catch (e) { return false; } } },

Decode information

To decode information from ADAMANT blockchain transaction you can use decodeMsg.js module. Reed more about Encrypting and Decrypting Messages at this page

Mode: synchronous

Module format

api.decodeMsg(msg, senderPublicKey, passPhrase, nonce):

  • msg — message you need to decrypt; mandatory,
  • senderPublicKey — senders' pablic key; mandatory
  • passPhrase — private recipint's passphrase; mandatory
  • nonce — nonce

Code examples:

  1. const chat = tx.asset.chat; if (chat){ msg = api.decodeMsg(chat.message, tx.senderPublicKey, config.passPhrase, chat.own_message).trim(); }
Clone this wiki locally