Skip to content

API Specification

Aleksei Lebedev edited this page Sep 30, 2019 · 31 revisions

The library allows to send and retrieve transactions/messages, get other blockchain data, and decode messages.

get(type, input)

Performs request to ADAMANT blockchain endpoints.

Parameters:

Supported endpoints (values of type parameters):

type API Request input Result
account /api/accounts?address= + [input] ADAMANT address Account's information
account_delegates /api/accounts/delegates?address= + [input] ADAMANT address Votes of specific ADAMANT account — list of delegates. Returned delegates field of result.
block /api/blocks/get?id= + [input] Block's id Full information about specific block
blocks /api/blocks + [input] Filter conditions List of blocks filtered by input. Returned blocks field of result.
states /api/states/get + [input] Filter conditions Fetch data from KVS
delegate /api/delegates/get?username= + [input] Delegate's name Information for delegete by username
delegate_voters /api/delegates/voters?publicKey= + [input] Delegate's publicKey List of delegete's voters
delegate_forged /api/delegates/forging/getForgedByAccount?generatorPublicKey= + [input] Delegate's publicKey Forging stats of delegate
transaction /api/transactions/get?id= + [input] Tx ID Transaction with specific ID
transactions /api/transactions? + [input] Filter conditions List of transactions filtered by input

Examples:

const txTrx = (await api.get(`transactions`, `fromHeight=` + (Store.lastHeight - 5) + `&and:recipientId=` + Store.user.ADM.address + `&and:type=0`)).transactions;

Any other ADAMANT endpoint can be requested — set type to uri and input to full endpoint with parameters.

Example:

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

syncGet(uri, isUrl, isNoJson)

Performs request to ADAMANT blockchain endpoints or custom URL using Promise.

Parameters:

  • uri — endpoint name or full custom url
  • isUrl — specify if uri is a custom URL. Default is false and uri refers to endpoint name.
  • isNoJson — set to true to get full response body. Default is false and JSON object returned.

Returns results of a request — JSON object or full response body depending on isNoJson parameter.

Examples:

const data = await api.syncGet(config.infoservice + `/get`, true);

const resp = await api.syncGet(`/api/states/get?senderId=${admAddress}&key=${coin.toLowerCase()}:address`);

send(passPhrase, address, payload, type, isEncode, amount_comment)

Creates Token Transfer or Chat transaction, signs it, and broadcasts to ADAMANT network. Supports Basic, Rich and Signal Message Types.

Parameters:

  • passPhrase — sender's passPhrase. Mandatory.
  • address — recepient's ADM address. Mandatory.
  • payload — amount to send for Token Transfer or message contents for Chat transaction. Amount is in ADM tokens. Message will be encrypted. Mandatory.
  • type — type of payload: tokens (default) for Token Transfer or message / rich / signal for Chat transaction. Optional.
  • isEncode — set to true in case you don't need to broadcast a formed transaction — function will return transaction object. Default is false and transaction will be broadcasted and its results are returned.
  • amount_comment — amount of ADM tokens to send with message. For Chat transactions only. Optional.

Returns results of proccessing a transaction or formed transaction object depending on isEncode parameter.

Examples:

let address = senderKvsOutAddress;
let value = outAmount;
let comment = '';

if (add_comment) {
	comment = `Hey, you are lucky! Waiting for new bets!`;
}

let res;
if (comment){
	res = api.send(User.passPhrase, address, comment, `message`, null, value);
} else {
	res = api.send(User.passPhrase, address, value);
}

console.log(`Send results: `, res);

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

decodeMsg(msg, senderPublicKey, passPhrase, nonce)

Decrypts a message.

Parameters:

  • msg — message to decrypt
  • senderPublicKey — sender's public key
  • passPhrase — recepient's 12 words Mnemonic ADM passPhrase
  • nonce — nonce

Returns decrypted message.

Example:

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