Skip to content

JSON RPC

martiliones edited this page May 26, 2024 · 33 revisions

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

To run commands with JSON-RPC, daemon should be started, and Adamant-console should be installed and configured.

Starting JSON-RPC daemon

To start JSON-RPC daemon you need to run Adamant-console with RPC server command.

It is highly recommended to run RPC server locally, as commands and results will contain sensitive data like passphrase.

Curl examples explained

curl examples below might return a response with error because of default content type, set on machine. On some servers --data option set to application/x-www-form-urlencoded by default, but application/json is needed. To fix this, set header by placing -H "Content-Type: application/json" for any command you run.

Here is an example:

curl -X POST --data '{"jsonrpc":"2.0","method":"accountNew","params":[],"id":64}' -H "Content-Type: application/json"

Examples below also suppose you run locally installed Adamant-console with port number set in configuration file. If you want to override it, set the last argument given to curl like http://127.0.0.1:5080.

Here is an example:

curl -X POST --data '{"jsonrpc":"2.0","method":"accountNew","params":[],"id":64}' -H "Content-Type: application/json" http://127.0.0.1:5080

JSON-RPC methods

JSON RPC API Reference

Commands

accountNew

It creates new ADAMANT account and provides account data.

Parameters

none

Returns
  • address — generated wallet's address
  • passphrase — generated wallet's passphrase
  • publicKey — generated wallet's publicKey
  • privateKey — generated wallet's privateKey
Example
// Request
curl -X POST --data '{"jsonrpc":"2.0","method":"accountNew","params":[],"id":64}'

// Result
{
  "jsonrpc": "2.0",
  "id": 64,
  "result": {
    "address": "U9258211749743252159",
    "passphrase": "inherit subject velvet trick air naive tobacco slide voyage urge absurd wheat",
    "publicKey": "e980d3f88768c143ac78469c64cdea5637e2da7578a46e12d8aba64dbe3da4c5",
    "privateKey": "d4f8f839513bb20801c132e7993245bc67a564c28b300181bd3abc196cb827c6e980d3f88768c143ac78469c64cdea5637e2da7578a46e12d8aba64dbe3da4c5"
  }
}

clientVersion

Returns current client (Adamant-console) version number.

Parameters

none

Returns

String result — client version

Example
// Request
curl -X POST --data '{"jsonrpc":"2.0","method":"clientVersion","params":[],"id":83}'

// Result
{
  "jsonrpc": "2.0",
  "id": 83,
  "result": "1.4.0"
}

delegateNew

Registers new ADAMANT delegate, if user has enough tokens (the registration fee) on account. Return data is in JSON format.

Current fee for registering as delegate is 3000 ADM.

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 !@$&_.

Returns
  • type — transaction type
  • timestamp — transaction timestamp
  • asset — delegate's data
  • id — transaction id
  • fee — transaction fee
  • senderId — sender Address
  • signature — transaction signature
  • senderPublicKey — sender's publicKey
Example
// Request
curl -X POST --data '{"jsonrpc":"2.0","method":"delegateNew","params":["delegate_name"],"id":38}'

// Result
{
  "success": true,
  "nodeTimestamp": 37489091,
  "transaction": {
    "type": 2,
    "amount": 0,
    "timestamp": 37489091,
    "asset": {
      "delegate": {
        "username": "delegate_name",
        "publicKey": "ae1cf99ade40ba4b94c8408ad440754e037b1837da256549d9b878629af23150"
      }
    },
    "senderPublicKey": "ae1cf99ade40ba4b94c8408ad440754e037b1837da256549d9b878629af23150",
    "senderId": "U2509016256839651561",
    "signature": "fe0b4747c698f9c01abd1680bb5087b8247719c20ec48522b16bc88ab54bf1f7871f2dc21cc5d8060fb10cc0ce520f43fa9e92bfc356449dbe9a9c7ca69ca604",
    "id": "6132068325824063462",
    "fee": 300000000000,
    "relays": 1,
    "receivedAt": "2018-11-10T14:38:11.224Z"
  }
}

getAddress

Returns information about specific ADAMANT address (account).

Address must be registered in network, it means it should have at least one income transaction. Other way method will throw not found error.

Public key will be null if address has no outcome transactions, such accounts are not initialized. It is impossible to send messages to uninitialized accounts.

Parameters

address: ADAMANT address to fetch information for

Returns
  • address` — address (account) id, like U1575910021083268491
  • unconfirmedBalance` — unconfirmed (pending) balance
  • balance` — confirmed balance
  • publicKey` — account public key
Example
// Request
curl -X POST --data '{"jsonrpc":"2.0","method":"getAddress","params":["U7972131227889954319"],"id":66}'

// Result
{
  "jsonrpc": "2.0",
  "id": 66,
  "result": {
    "address": "U7972131227889954319",
    "unconfirmedBalance": "103730137053",
    "balance": "103730137053",
    "publicKey": "d2885bc8d4aa68f0f4c919077c1edcb9c9020a715f20cb6db7578cd6f68055bb",
    "unconfirmedSignature": 0,
    "secondSignature": 0,
    "secondPublicKey": null,
    "multisignatures": [],
    "u_multisignatures": []
  }
}

getBlock

Returns information about specific block in blockchain.

Parameters

block: block number

Returns
  • id — block number
  • timestamp — block timestamp
  • height — block height
  • previousBlock — previous block number
  • numberOfTransactions — number of transactions in block
  • totalAmount — total amount transferred in block
  • totalFee — total fee for all transactions in block
  • reward — reward of this block forger
  • totalForged — totalFee + reward
  • generatorPublicKey — public key of block forger
  • generatorId — address of block forger
  • blockSignature — block signature
  • confirmations — confirmations by network
Example
// Request
curl -X POST --data '{"jsonrpc":"2.0","method":"getBlock","params":["14889898444351917543"],"id":67}'

// Result
{
  "jsonrpc": "2.0",
  "id": 64,
  "result": {
    "id": "14889898444351917543",
    "version": 0,
    "timestamp": 39479845,
    "height": 6454608,
    "previousBlock": "11485783042671812125",
    "numberOfTransactions": 1,
    "totalAmount": 10000000,
    "totalFee": 50000000,
    "reward": 50000000,
    "payloadLength": 117,
    "payloadHash": "f031d178ea317c4a32c3e40f60f56cabd76498a3bc1b67738376f474b1d11c25",
    "generatorPublicKey": "2fb8345eb09b9fd231727ef5f094835abac6e8001222db08f1c60187a4ea5c4d",
    "generatorId": "U699797837045412092",
    "blockSignature": "074cbccee8588be79a2bafaab9393047ae4389633250388461a0c571ebe188464071b01c4c4fa1b577eab544560212c4b96c164cc0ff45bc9218c817baf29707",
    "confirmations": 20028451,
    "totalForged": "100000000"
  }
}

getBlocks

Returns blocks for the defined criteria. Conditions are written in Transactions-Query-Language.

Parameters

condition: array of conditions

Returns

Array of blocks.

Example
// Request
curl -X POST --data '{"jsonrpc":"2.0","method":"getBlocks","params":["height=1","orderBy=timestamp:desc"],"id":96}'

// Result
{
  "jsonrpc": "2.0",
  "id": 64,
  "result": {
    "id": "14889898444351917543",
    "version": 0,
    "timestamp": 39479845,
    "height": 6454608,
    "previousBlock": "11485783042671812125",
    "numberOfTransactions": 1,
    "totalAmount": 10000000,
    "totalFee": 50000000,
    "reward": 50000000,
    "payloadLength": 117,
    "payloadHash": "f031d178ea317c4a32c3e40f60f56cabd76498a3bc1b67738376f474b1d11c25",
    "generatorPublicKey": "2fb8345eb09b9fd231727ef5f094835abac6e8001222db08f1c60187a4ea5c4d",
    "generatorId": "U699797837045412092",
    "blockSignature": "074cbccee8588be79a2bafaab9393047ae4389633250388461a0c571ebe188464071b01c4c4fa1b577eab544560212c4b96c164cc0ff45bc9218c817baf29707",
    "confirmations": 20028451,
    "totalForged": "100000000"
  }
}

getDelegate

Returns information about specific delegate.

Parameters

delegate: delegate name

Returns
  • username — delegate's Username
  • address — delegate's Address
  • publicKey — delegate's publicKey
  • vote — vote weight in older system (not used)
  • votesWeight — vote weight in Fair dPoS
  • producedblocks — number of forged block
  • missedblocks — number of missed blocks
  • rank — position in delegate rating
Example
// Request
curl -X POST --data '{"jsonrpc":"2.0","method":"getDelegate","params":["lake"],"id":68}'

// Result
{
  "jsonrpc": "2.0",
  "id": 68,
  "result": {
    "username": "lake",
    "address": "U11733940627707637103",
    "publicKey": "ad52d6dda80bcf930da0b467c24824d40940bbbff3a4989db4878e75ead2d260",
    "vote": "192659479218070",
    "votesWeight": "2268634140885",
    "producedblocks": 61076,
    "missedblocks": 268,
    "rate": 106,
    "rank": 106,
    "approval": 0.02,
    "productivity": 0
  }
}

getMessage

Returns information about specific message and decoded it if passphrase provided. Returns error if message can't be decoded, or if transaction is not of chat type 8.

Parameters
  • txId: transaction id
  • passphrase (optional): passphrase of account able to decrypt. If not set, passphrase form config file is used
Returns
  • id — transaction id
  • timestamp — transaction timestamp
  • height — transaction height
  • type — transaction type
  • amount — transaction amount
  • fee — transaction fee
  • senderId — sender Address
  • senderPublicKey — sender's publicKey
  • recipientId — recipient Address (if transaction has recipient)
  • recipientPublicKey — recipient's publicKey (if transaction has recipient)
  • signature — transaction signature
  • confirmations — confirmations number
  • asset — message decoded contents

asset can be Basic Encrypted Message, or may include Rich Text Asset.

Example
// Request
curl -X POST --data '{"jsonrpc":"2.0","method":"getMessage","params":["16723092651258984040"],"id":69}'

// Result
{
  "jsonrpc": "2.0",
  "id": 69,
  "result": {
    "id": "16723092651258984040",
    "height": 40589982,
    "blockId": "13954358562032326497",
    "type": 8,
    "block_timestamp": 212365615,
    "timestamp": 212365610,
    "senderPublicKey": "1ed651ec1c686c23249dadb2cb656edd5f8e7d35076815d8a81c395c3eed1a85",
    "senderId": "U3716604363012166999",
    "recipientId": "U15531909278942872097",
    "recipientPublicKey": "fb736e72b4df38d973f0f8dfccbece763ab0d9603897dfa8f1167fa50018a8e0",
    "amount": 1000000,
    "fee": 50000000,
    "signature": "7c42ef52a6d81dc210e85577a4b68367faaf0a1d7f24f772fbdf07ece5750d378359b8a64fd78726aa56fb2451ad8883e7a4fa31a72dda25e3bf2140b4d0f60f",
    "signatures": [],
    "confirmations": 260,
    "asset": {
      "chat": {
        "message": "785b2e406f94aa5e6331df085eb3a3f47f188a85957ab96484",
        "own_message": "65068b4005663674cbad071489bfb841f69e5bb75f51bd5c",
        "type": 1
      }
    },
    "decoded": "Hello-ADM"
  }
}

getTransaction

Returns information about specific transaction.

Parameters

txId: transaction id

Returns
  • id — transaction id
  • timestamp — transaction timestamp
  • height — transaction height
  • type — transaction type
  • amount — transaction amount
  • fee — transaction fee
  • senderId — sender Address
  • senderPublicKey — sender's publicKey
  • recipientId — recipient Address (if transaction has recipient)
  • recipientPublicKey — recipient's publicKey (if transaction has recipient)
  • signature — transaction signature
  • confirmations — confirmations number
Example
// Request
curl -X POST --data '{"jsonrpc":"2.0","method":"getTransaction","params":["9032456563660766013"],"id":69}'

// Result
{
  "jsonrpc": "2.0",
  "id": 69,
  "result": {
    "id": "9032456563660766013",
    "height": 6470038,
    "blockId": "8498563092326573696",
    "type": 9,
    "timestamp": 39557274,
    "senderPublicKey": "741d3d1f52e609eef981e9ab370ec1e7c3ff70cafad94691937a2bb6d84bbff2",
    "senderId": "U9203183357885757380",
    "recipientId": null,
    "recipientPublicKey": null,
    "amount": 0,
    "fee": 100000,
    "signature": "c8508a7acc9056e485ec40e9ef3805dd113e4f6ac8088e1ee12ac468b2531e987dff50227b73ea725ab46d1a05f0e9615a1525191b174a4e786871df0c77710f",
    "signatures": [],
    "confirmations": 886,
    "asset": {}
  }
}

getTransactions

Returns transactions with the defined criteria. Conditions are written in Transactions-Query-Language.

Parameters

condition: array of conditions

Returns

Array of transactions.

Example
// Request
curl -X POST --data '{"jsonrpc":"2.0","method":"getTransactions","params":["inId=U7972131227889954319","and:type=0","limit=1","orderBy=timestamp:desc"],"id":70}'

// Result
{
  "jsonrpc": "2.0",
  "id": 70,
  "result": [{
    "id": "11851566466898162941",
    "height": 6471819,
    "blockId": "3727391880396723759",
    "type": 0,
    "timestamp": 39566268,
    "senderPublicKey": "cdab95b082b9774bd975677c868261618c7ce7bea97d02e0f56d483e30c077b6",
    "senderId": "U15423595369615486571",
    "recipientId": "U9781760580710719871",
    "recipientPublicKey": "b0b4d346382aa07b23c0b733d040424532201b9eb22004b66a79d4b44e9d1449",
    "amount": 10000000,
    "fee": 50000000,
    "signature": "093aa02d72860c6412bf7a48ca1386687fed9e2a0c0cf50d49ca87dfe88fc3a11f3984b769989212db93461e62ef3adcbac976147bf38b9eccc61bbb95f0390c",
    "signatures": [],
    "confirmations": 296,
    "asset": {}
  }]
}

getTransactionsInBlockById

Returns transactions within specific Block by BlockId.

Parameters

blockId: block id to fetch transactions for

Returns

Array of transactions.

Example
// Request
curl -X POST --data '{"jsonrpc":"2.0","method":"getTransactionsInBlockById","params":["5404511181402858957"],"id":94}'

// Result
{
  "jsonrpc": "2.0",
  "id": 94,
  "result": [{
    "id": "585831903148012085",
    "height": 6627558,
    "blockId": "5404511181402858957",
    "type": 0,
    "timestamp": 40353194,
    "senderPublicKey": "cdab95b082b9774bd975677c868261618c7ce7bea97d02e0f56d483e30c077b6",
    "senderId": "U15423595369615486571",
    "recipientId": "U6403295799329051468",
    "recipientPublicKey": null,
    "amount": 10000000,
    "fee": 50000000,
    "signature": "7b15e4fa993e8a83674d499e23cc1e92e7b8e329305bd638b52b7bf8d8ef309e5e3918fe2265824569e444b8e7118e8bf7077aedf91065bb0c411545d1a49a02",
    "signatures": [],
    "confirmations": 2128,
    "asset": {}
  }]
}

getTransactionsInBlockByHeight

Returns transactions within specific Block by its height.

Parameters

height: height of the block to fetch transactions for

Returns

Array of transactions.

Example
// Request
curl -X POST --data '{"jsonrpc":"2.0","method":"getTransactionsInBlockByHeight","params":["6627558"],"id":95}'

// Result
{
  "jsonrpc": "2.0",
  "id": 95,
  "result": [{
    "id": "585831903148012085",
    "height": 6627558,
    "blockId": "5404511181402858957",
    "type": 0,
    "timestamp": 40353194,
    "senderPublicKey": "cdab95b082b9774bd975677c868261618c7ce7bea97d02e0f56d483e30c077b6",
    "senderId": "U15423595369615486571",
    "recipientId": "U6403295799329051468",
    "recipientPublicKey": null,
    "amount": 10000000,
    "fee": 50000000,
    "signature": "7b15e4fa993e8a83674d499e23cc1e92e7b8e329305bd638b52b7bf8d8ef309e5e3918fe2265824569e444b8e7118e8bf7077aedf91065bb0c411545d1a49a02",
    "signatures": [],
    "confirmations": 2200,
    "asset": {}
  }]
}

getTransactionsReceivedByAddress

Returns received transactions for specific ADAMANT address.

Parameters

address: ADAMANT address to fetch information for

Returns

Array of transactions.

Example
// Request
curl -X POST --data '{"jsonrpc":"2.0","method":"getTransactionsReceivedByAddress","params":["U9781760580710719871"],"id":80}'

// Result
{
  "jsonrpc": "2.0",
  "id": 80,
  "result": [{
    "id": "7998779498446428408",
    "height": 6484755,
    "blockId": "5826271645701856620",
    "type": 0,
    "timestamp": 39633602,
    "senderPublicKey": "d2885bc8d4aa68f0f4c919077c1edcb9c9020a715f20cb6db7578cd6f68055bb",
    "senderId": "U7972131227889954319",
    "recipientId": "U9781760580710719871",
    "recipientPublicKey": "b0b4d346382aa07b23c0b733d040424532201b9eb22004b66a79d4b44e9d1449",
    "amount": 10000000,
    "fee": 50000000,
    "signature": "1d0eafa1256c1fcb8b366c202ff7b1547c66f61db4c466a9a2999d23e7621c8bbc1e1f40a6ffc9341c9d10c3cda964fad53e3ada0f39272ef5b55d8237df2b0f",
    "signatures": [],
    "confirmations": 167,
    "asset": {}
  }, {
    "id": "11851566466898162941",
    "height": 6471819,
    "blockId": "3727391880396723759",
    "type": 0,
    "timestamp": 39566268,
    "senderPublicKey": "cdab95b082b9774bd975677c868261618c7ce7bea97d02e0f56d483e30c077b6",
    "senderId": "U15423595369615486571",
    "recipientId": "U9781760580710719871",
    "recipientPublicKey": "b0b4d346382aa07b23c0b733d040424532201b9eb22004b66a79d4b44e9d1449",
    "amount": 10000000,
    "fee": 50000000,
    "signature": "093aa02d72860c6412bf7a48ca1386687fed9e2a0c0cf50d49ca87dfe88fc3a11f3984b769989212db93461e62ef3adcbac976147bf38b9eccc61bbb95f0390c",
    "signatures": [],
    "confirmations": 13103,
    "asset": {}
  }]
}

nodeHeight

Returns current node height.

Parameters

none

Returns

Number result — node height

Example
// Request
curl -X POST --data '{"jsonrpc":"2.0","method":"nodeHeight","params":[],"id":81}'

// Result
{
  "jsonrpc": "2.0",
  "id": 81,
  "result": 6504672
}

nodeVersion

Returns node version.

Parameters

none

Returns
  • commit — Git commit hash for current node build
  • version — current node version
Example
// Request
curl -X POST --data '{"jsonrpc":"2.0","method":"nodeVersion","params":[],"id":82}'

// Result
{
  "jsonrpc": "2.0",
  "id": 82,
  "result": {
    "commit": "f78450287405a8787b727f88cc08c81f60c95efb",
    "version": "0.4.1"
  }
}

sendTokens

Send tokens to specific ADAMANT address.

Parameters
  • address: ADAMANT address to send tokens to
  • amount: amount to send. It is integer amount of 1/10^8 ADM tokens (1 ADM = 100000000)
  • passphrase (optional): passphrase of account to send from. If not set, passphrase from config file is used
Returns

Number — transaction Id

Example
// Request
curl -X POST --data '{"jsonrpc":"2.0","method":"sendTokens","params":{"address":"U7972131227889954319", "amount":"10000000"},"id":65}'

// Result
{
  "jsonrpc": "2.0",
  "id": 65,
  "result": "4730418426961061259"
}

sendMessage

Send message to specific ADAMANT address.

Parameters
  • address: ADAMANT address to send tokens to
  • message: text message to send. Text will be encrypted as specified in AIP-4: Basic Encrypted Messages. Node accepts maximum encrypted text length of 20480 hex symbols, so approximate maximum unencrypted text length is about 13000 UTF-8 symbols. Transaction fee depends on text length, and approximately 0.001 ADM per 255 unencrypted symbols.
  • amountString: amount to send. It is string amount of 1/10^8 ADM tokens (1 ADM = 100000000)
  • passphrase (optional): passphrase of account to send from. If not set, passphrase from config file is used
Returns

transactionId — transaction Id

Example
// Request
curl -X POST --data '{"jsonrpc":"2.0","method":"sendMessage","params":{"address":"U7972131227889954319", "amount":"10000000", "message": "Hello, world!" },"id":65}'

// Result
{
  "success": true,
  "nodeTimestamp": 37486967,
  "transactionId": "18412470054836757895"
}

sendRich

Additionally to send message, Console offers to send rich messages.

Parameters
  • address: ADAMANT address to send tokens to
  • json: An object describing rich message. JSON will be encrypted before broadcasting transaction.
  • passphrase (optional): passphrase of account to send from. If not set, passphrase from config file is used
Returns

transactionId — transaction Id

Example
// Request
curl -X POST --data '{"jsonrpc":"2.0","method":"sendRich","params":{"address":"U7972131227889954319", "json": { "type": "eth_transaction", "text_fallback": "Ether transactions are not supported by application yet", "amount": "0.002", "comments": "I like to send it, send it", "hash": "0xfa46d2b3c99878f1f9863fcbdb0bc27d220d7065c6528543cbb83ced84487deb"} },"id":65}'

// Result
{
  "success": true,
  "nodeTimestamp": 37486967,
  "transactionId": "18412470054836757895"
}

sendSignal

Additionally to send message, Console offers to send signal messages.

Parameters
  • address: ADAMANT address to send tokens to
  • json: An object describing signal message. JSON will be encrypted before broadcasting transaction.
  • passphrase (optional): passphrase of account to send from. If not set, passphrase form config file is used
Returns

transactionId — transaction Id

Example
// Request
curl -X POST --data '{"jsonrpc":"2.0","method":"sendSignal","params":{"address":"U7972131227889954319", "json": { "type": "eth_transaction", "text_fallback": "Ether transactions are not supported by application yet", "amount": "0.002", "comments": "I like to send it, send it", "hash": "0xfa46d2b3c99878f1f9863fcbdb0bc27d220d7065c6528543cbb83ced84487deb"} },"id":65}'

// Result
{
  "success": true,
  "nodeTimestamp": 37486967,
  "transactionId": "18412470054836757895"
}

voteFor

Vote for delegate in ADAMANT blockchain.

Parameters
  • votes: Array of delegates' public keys or ADM addresses or delegate names. For upvote, add leading + to delegate's id. For downvote, add leading - to delegate's id.
  • passphrase (optional): passphrase of account to send from. If not set, passphrase form config file is used
Returns

transactionId — transaction Id

Example
// Request
curl -X POST --data '{"jsonrpc":"2.0","method":"voteFor","params":{ "votes": ["+d2885bc8d4aa68f0f4c919077c1edcb9c9020a715f20cb6db7578cd6f68055bb", "-lynx", "+U777355171330060015" ] },"id":65}'

// Result
{
  "success": true,
  "nodeTimestamp": 37486967,
  "transactionId": "18412470054836757895"
}