Skip to content

Running Commands in Adamant library

martiliones edited this page Jan 26, 2024 · 5 revisions

You can use Adamant-console as a library for NodeJS, but the preferred way to interact with Adamant via JavaScript is adamant-api-jsclient.

Getting started

To begin with, you need to install and configure adamant-console (see wiki for details). Then import the module into your code:

const adamantApi = require('adamant-console');

Example of using:

const adamantApi = require('adamant-console');

adamantApi.getNodeVersion()
  .then((res) => {
    console.log(res);
    process.exit();
  })
  .catch((err) => console.error(err));

Account

createAccount: () => Object

Creates a new Adamant account

Example:

const res = adamantApi.createAccount();

console.log(res);

Delegate

createDelegate: (username: String, passphrase?: String) => Promise

Registers user account as delegate

Parameters:

  • username - Delegate name you want to register with. It must be unique in ADAMANT blockchain. It should not be similar to ADAMANT address. Delegate name can only contain alphanumeric characters and symbols !@$&_.
  • passphrase - (optional, if set in the config) account passphrase

Example:

adamantApi.createDelegate('username')
  .then((res) => console.log(res));

Get

getAddress: (address: String) => Promise

Gets actual account's information in ADAMANT blockchain

Parameters:

  • address - ADAMANT address starting with U, string

Example:

adamantApi.getAddress('U777355171330060015')
  .then((res) => console.log(res));

getBlock: (id: String) => Promise

Gets full information about special block of ADAMANT chain

Parameters:

  • id - block's id

Example:

adamantApi.getBlock('11114690216332606721')
  .then((res) => console.log(res));

getBlocks: (...queries: [String]) => Promise

Gets list of blocks in ADAMANT chain

Parameters:

Example:

adamantApi.getBlocks('limit=5', 'offset=12')
  .then((res) => console.log(res));

getDelegate: (username: String) => Promise

Gets delegate

Parameters:

  • username - delegate's username

Example:

adamantApi.getDelegate('lynx')
  .then((res) => console.log(res));

getMessage: (id: String) => Promise

Gets information about specific transaction's asset with transaction id as a parameter.

Parameters:

  • id - transaction id

Example:

adamantApi.getMessage('12154642911137703318')
  .then((res) => console.log(res));

getTransaction: (id: String) => Promise

Gets information about specific transaction with transaction id as a parameter.

Parameters:

  • id - transaction id

Example:

adamantApi.getTransaction('12154642911137703318')
  .then((res) => console.log(res));

getTransactions: (...queries) => Promise

Gets information about the transactions.

Parameters:

Example:

adamantApi.getTransactions('limit=1')
  .then((res) => console.log(res));

getTransactionsInBlockById: (blockId: String) => Promise

Gets information about the transactions in the specified block by id.

Parameters:

  • blockId - block's id

Example:

adamantApi.getTransactionsInBlockById('12154642911137703318')
  .then((res) => console.log(res));

getTransactionsInBlockByHeight: (height: String) => Promise

Gets information about the transactions in the specified block by height.

Parameters:

  • height - block's height

Example:

adamantApi.getTransactionsInBlockByHeight('12154642911137703318')
  .then((res) => console.log(res));

getTransactionsReceivedByAddress: (address: String) => Promise

Gets information about the received transactions by address.

Parameters:

  • address - block's address

Example:

adamantApi.getTransactionsReceivedByAddress('12154642911137703318')
  .then((res) => console.log(res));

Node

getNodeHeight: () => Promise

Gets the current node height

Example:

adamantApi.getNodeHeight()
  .then((res) => console.log(res));

getNodeVersion: () => Promise

Gets the current node version

Example:

adamantApi.getNodeVersion()
  .then((res) => console.log(res));

Send

sendTokens: (address: String, amountString: String, passPhrase?: String) => Promise

Creates Token Transfer transaction, signs it, and broadcasts to ADAMANT network. See https://github.com/Adamant-im/adamant/wiki/Transaction-Types#type-0-token-transfer-transaction

Example:

adamantApi.sendTokens(
  'U6386412615727665758',
  '10000ADM',
  'only ladder great same figure click organ metal main tide expand protect',
)
  .then((res) => console.log(res));

sendMessage: (address: String, message: String, amountString?: String, passphrase?: String) => Promise

Encrypts a message, creates Message transaction, signs it, and broadcasts to ADAMANT network.

Example:

adamantApi.sendMessage(
  'U6386412615727665758',
  {/* message object */},
  '10000ADM',
  'only ladder great same figure click organ metal main tide expand protect',
)
  .then((res) => console.log(res));

sendRich: (address: String, json: String, passphrase?: String) => Promise

Encrypts a rich message, creates Message transaction, signs it, and broadcasts to ADAMANT network.

Example:

adamantApi.sendRich(
  'U6386412615727665758',
  {/* rich message object */},
  'only ladder great same figure click organ metal main tide expand protect',
)
  .then((res) => console.log(res));

sendSignal: (address: String, json: String, passPhrase?: String) => Promise

Encrypts a signal message, creates Message transaction, signs it, and broadcasts to ADAMANT network.

Example:

adamantApi.sendSignal(
  'U6386412615727665758',
  {/* signal message object */},
  'only ladder great same figure click organ metal main tide expand protect',
)
  .then((res) => console.log(res));

Vote

voteFor(delegates: String[], passPhrase?: String)

Creates Vote For Delegate transactions, signs it, and broadcasts to ADAMANT network.

Parameters:

  • delegates - PublicKeys, ADM addresses and delegate names for upvote and downvote. Downvote vote should contain - in first place. It would be more efficient to pass publicKey, otherwise the api will make additional queries
  • passPhrase - (optional, if set in the config) account pass phrase

Example:

adamantApi.voteFor(
  [
  'lynx',
  '+U777355171330060015',
  '-a9407418dafb3c8aeee28f3263fd55bae0f528a5697a9df0e77e6568b19dfe34'
  ],
  'only ladder great same figure click organ metal main tide expand protect',
)
  .then((res) => console.log(res));