Skip to content

JSON RPC

zyuhel edited this page Dec 13, 2018 · 33 revisions

Starting JSON-RPC daemon

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

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 we need application/json. 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"

The examples below 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


accountNew

It creates new ADAMANT account and provide account data.

Parameters

none

Returns
  • address - Generated wallet address
  • passPhrase - Generated wallet passphrase
  • publicKey - Generated wallet publicKey
  • privateKey- Generated wallet 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 version

Parameters

none

Returns

String - 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"
}

getAddress

Returns information about specific ADAMANT address.

Please note that if account hasn't made any receiving/sending transaction, it can throw not found error.

Parameters

address: ADAMANT address to fetch information for

Returns
  • address - address name
  • unconfirmedBalance - unconfirmed balance
  • balance - confirmed balance
  • publicKey - account publickey
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

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 of tokens in this block (fee + forged)
  • totalFee -
  • reward -
  • payloadLength -
  • payloadHash -
  • generatorPublicKey - Public key of block forger
  • generatorId - Address of block forger
  • blockSignature - block signature
  • confirmations - confirmations
Example
// Request
curl -X POST --data '{"jsonrpc":"2.0","method":"getBlock","params":["14889898444351917543"],"id":67}'

// Result
{
	"jsonrpc": "2.0",
	"id": 67,
	"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": 54,
		"totalForged": "100000000"
	}
}

getDelegate

Returns information about specific delegate

Parameters

delegate: delegate name

Returns
  • username - Delegate Username
  • address - Delegate Address
  • publicKey - Delegate publicKey
  • vote - Vote Weight in older system
  • 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
	}
}

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 publicKey
  • recipientId - Recipient Address (if transaction have recipient)
  • recipientPublicKey - Recipient publicKey (if transaction have recipient)
  • signature - Transaction signature
  • confirmations - confirmations
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","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": {}
	}]
}

getTransactionsReceivedByAddress

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

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 - 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

It send tokens to specific ADAMANT address

Parameters
  • address: ADAMANT address to send tokens to
  • amount: Amount of tokens to send
  • passphrase (optional): passphrase of account to use, if not given the one from config is used.
Returns

Number - new 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"
}
Clone this wiki locally