Skip to content

Running Commands in Adamant console

martiliones edited this page Feb 23, 2024 · 14 revisions

To run commands in ADAMANT blockchain, Adamant-console should be installed and configured.

There are 3 ways of interacting with ADAMANT blockchain using Adamant-console. You can use command-line interface (CLI), JSON-RPC, or as a JS library.

Adamant-console modes for CLI

Commands can be run in interactive mode, or non-interactively.

If you run Adamant-console with simple adm command, it will start interactive mode.

adm #will run interactive mode

Then, to exit Adamant-console, press Ctrl+C twice.

If you run Adamant-console with a particular command, it will make an action and then return to bash.

adm account new #will create new ADAMANT account and return to bash

Choosing ADAMANT account to interact with

If command needs an account to run, f. e. send tokens, the account can be set in two ways, by editing config file, or by placing --passphrase command parameter.

Note, that --passphrase command parameter has more priority, than passphrase parameter in config.

Example:

adm send tokens U15531909278942872097 1ADM --passphrase "shift credit run sea order flower tribe invest march govern blanket absorb"

Sends 1 ADM to U15531909278942872097.

Running commands in other programs

You can run any command from bash, or use any programming languages to interact with Adamant-console, like PHP, Python, NodeJS. Here is an example of creating new ADAMANT account in PHP:

<?php

//If Adamant-console installed globally via NPM
$path_to_adamant_console='adm';

//If Adamant-console installed locally
//$path_to_adamant_console='node ./bin/adamant.js';

//Creating new ADAMANT wallet
exec($path_to_adamant_console.' account new', $json_answer);

//Processing result
$json_answer=implode('', $json_answer);
$answer=json_decode($json_answer);

if ($answer->success) {
    echo "\n\nNew ADAMANT wallet ".$answer->account->address." is created. Its passphrase: ".$answer->account->passphrase."\n\n";
}
else {
    echo "\n\nWallet was not created.\n\n";
}

Using JSON-RPC

If you prefer to use JSON-RPC instead of CLI, welcome. See JSON-RPC configuration and usage.

Console as a JS library

You can add Console as a dependency in a JS project.