Coin Daemon


Daemon JSON RPC API

Daemon JSON RPC is a HTTP server which provides JSON 2.0 RPC interface for interacting with Daemon and Block Explorer.

Interacting with the API

To start the Daemon JSON RPC API server at http://localhost:31000/json_rpc run:

./ultranoted --rpc-bind-port=31000

To make the server accessible from another computer, use the --rpc-bind-ip 0.0.0.0 switch.

./ultranoted --rpc-bind-ip=0.0.0.0 --rpc-bind-port=31000

To make a JSON RPC request to your Daemon RPC you should use a POST request that looks like this:

http://localhost:31000/json_rpc

Parameter Description

service address

IP of Daemon RPC, if it is located on local machine it is either 127.0.0.1 or localhost

Using PHP

Configuration and instantiation

Once the rpc service is installed you should be able to send post requests to the and address looking like:

http://<service address>:<service port>/json_rpc

Now, to install the php library, download it and put it in the according folder, then include where needed :

Then, To start using the offered functions, you need to create an object as follows:

require_once( 'ultranote-rpc-php.php' ); $config = [ 'rpcUrl' => 'http://localhost:8060/json_rpc', 'rpcUser' => 'theusername', 'rpcPassword' => 'thepassword' ]; $coin = new XunCoin($config);

Parameter Description

$config['rpcUrl']

The link to the RPC service

$config['rpcUser']

The username of the RPC service (leave empty if none)

$config['rpcPassword']

The Password of the RPC service (leave empty if none)

getStatus()

Returns the blockCount of the deamon, usefull to check if the daemon is syncronized. $coin->getStatus()->blockCount;

Expected output:

39375

createAddress()

Create a new wallet. $coin->createAddress();

Expected output:

'XunG5DVpjrpNJ2JngzwaPS15iEySg2SVggQPArXzDVpJCEgHM5yhHPSR7X6nPg7E3sfN5CzibcUqXqmqMFj4DV3xgL5TsPEsCw'

deleteAddress($address)

Create a new wallet. $address = 'XunG5DVpjrpNJ2...'; $coin->deleteAddress($address);

Expected output:

true
Parameter Description

$address

The address to delete

getBalance($address)

Returns the balance of the given address $address = 'XunG5DVpjrpNJ2...'; $coin->deleteAddress($address);

Expected output:

135.32
Parameter Description

$address

The address to check

getUnconfirmedTransactionHashes($address)

Returns the unconfirmed transactions concerning the given address, can be used to check if there are new transactions in the pool. $address = 'XunG5DVpjrpNJ2...'; $coin->getUnconfirmedTransactionHashes($address);

Expected output:

{'7031309d4a0d87241c3700cafaeeefc04b226dc3387cedef4e93226aa76f21cb', '7031309d4a0d87241c3700cafaeeefc04b226dc3387cedef4e93226aa76f21cb'}
Parameter Description

$address

The address to check

getTransactions($firstBlockIndex,$blockCount)

Returns all the 'N' transactions that happened starting a given block. $firstBlockIndex = 39075; $blockCount=2; $coin->getTransactions($firstBlockIndex,$blockCount);

Expected output:

{( [blockHash] => '5acd33b287a2ed31f7a15e34f06a199739577c5cd83ce593170c6c2b034662d2' [transactions] => {} ), ( [blockHash] => '327e11cec4ffc46bb669477fba434e3c60f36c9ffc0c223c52f30d7b3ff96e73' [transactions] => {} )}
Parameter Description

$firstBlockIndex

The first block to start from

$blockCount

The number of blocks to analyse for transactions

getTransaction($transactionHash)

Returns the details of a given transaction. $transactionHash = '9fb36d4bb905ef360c877ce8eba9c9dafc81da27cae85bd4727af46c5ba75ef7'; $coin->getTransaction($transactionHash);

Expected output:

( [amount] => -1100000 [blockIndex] => 356658 [confirmations] => 87 [extra] => '0184fc63971f7a884edd6c79d30bf96b1958bcae9b9413fa29da9d033b187fe275' [fee] => 100000 [isBase] => [paymentId] => [state] => 0 [timestamp] => 1556123357 [transactionHash] => '4730d061536e6333dcfcc983b11dd87b1412101f139ca60a5c459032b0efc643' [transfers] =>{( [address] => 'Xun3n2BQZbSYSDPV...' [amount] => 1000000 [type] => 0 ),( [address] => 'Xun3W7YCR6efQGG...' [amount] => 5900000 [type] => 2 ),( [address] => 'Xun3W7YCR6efQG...' [amount] => -7000000 [type] => 0 ) )} [unlockTime] => 0 )
Parameter Description

$transactionHash

The hash of the transaction you are interested in

sendTransaction($from,$to,$ammount)

Sends an ammount of Xun from one address to an other. $from = 'Xun3n2BQZbSYSDPV2...'; $to='Xun3W7YCR6efQ...'; $ammount=1100000; $coin->sendTransaction($from,$to,$ammount);

Expected output:

'a599cbd0616c60e0ea75aaaac1c79dd8ba23e1ab50eeed6fc48206ec13fd8828'
Parameter Description

$from

The address of the sender of the currency

$to

The address of the recipient of the currency

$ammount

Ammount of currency to send

sendTransactionAdvanced($params)

Same as the sendTransaction function, with more options. $params = [ "addresses"=>["Xun3n2BQZbSYS..."], "anonymity"=> 2, "fee"=> 100000, "transfers"=>[ [ "amount"=>1000000, "address"=>"Xun3W7YCR6efQ..." ], [ "amount"=>3000000, "address"=>"Xun3cs87FJL5r..." ] ]]; $coin->sendTransactionAdvanced($params);

Expected output:

'a599cbd0616c60e0ea75aaaac1c79dd8ba23e1ab50eeed6fc48206ec13fd8828'
Parameter Description

$params['addresses']

Array of Addresses, Addresses which should be charged. Be careful, If you didn't specify addresses the daemon can charge all wallets to collets needed amount.

$params['anonymity']

The anonymity level of the transaction

$params['fee']

The fee that you are willing to pay for the transaction

$params['transfers']

Array of Arrays, Contains couples [ammount, address] of all the transfers you want to execute within the transaction

reset()

Re-sync cointainer starting from 0 block.

save()

Save current container state. Do it before making reserve copies or reboots.

Using Bash

Configuration and instantiation

Once the rpc service is installed you should be able to send post requests to the and address looking like:

http://<service address>:<service port>/json_rpc

getStatus

Returns the blockCount of the deamon, usefull to check if the daemon is syncronized. curl -d '{"method":"getStatus", "params": {},"jsonrpc": "2.0", "id": "1"}' http://username:[email protected]:8070/json_rpc

Expected output:

{ "id":"1", "jsonrpc":"2.0", "result":{ "blockCount":30375, "knownBlockCount":30375, "lastBlockHash":"ffa6dda0facc4a7ea903b0cededd897d2f281ac09eb6f50b9fed840dfe5073b5", "peerCount":22 } }

createAddress

Create a new wallet. curl -d '{"method":"createAddress","params": {},"jsonrpc": "2.0", "id": "1"}' http://username:[email protected]:8070/json_rpc

Expected output:

{ "id":"1", "jsonrpc":"2.0", "result":{ "address":"Xun3sfN5CzibcUqXqmqMFngzwaPS15..." } }

deleteAddress

Create a new wallet. curl -d '{"method":"deleteAddress","params": {"address":"Xun3sfN5CzibcUqXqmqMFngzwa..."},"jsonrpc": "2.0", "id": "1"}' http://username:[email protected]:8070/json_rpc

Expected output:

{ "id":"1", "jsonrpc":"2.0", "result":{} }
Parameter Description

address

The address to delete

getBalance

Create a new wallet. curl -d '{"method":"getBalance","params": {"address":"Xun3sfN5CzibcUqXqmqMFngzwa..."},"jsonrpc": "2.0", "id": "1"}' http://username:[email protected]:8070/json_rpc

Expected output:

{ "id":"1", "jsonrpc":"2.0", "result":{ "availableBalance":0, "lockedAmount":0 } }
Parameter Description

address

The address to check

getUnconfirmedTransactionHashes

Returns the unconfirmed transactions concerning the given address, can be used to check if there are new transactions in the pool. curl -d '{"method":"getUnconfirmedTransactionHashes","params": {"address":"Xun3sfN5Czibc..."},"jsonrpc": "2.0", "id": "1"}' http://username:[email protected]:8070/json_rpc

Expected output:

{ "id":"1", "jsonrpc":"2.0", "result":{ "transactionHashes":[ "7031309d4a0d87241c3700cafaeeefc04b226dc3387cedef4e93226aa76f21cb", "7031309d4a0d87241c3700cafaeeefc04b226dc3387cedef4e93226aa76f21cb" ] } }
Parameter Description

address

The address to check

getTransactions

Returns all the 'N' transactions that happened starting a given block. curl -d '{"method":"getTransactions","params": {"firstBlockIndex": 53888, "blockCount": 5},"jsonrpc": "2.0", "id": "1"}' http://username:[email protected]:8070/json_rpc

Expected output:

{ "id":"1", "jsonrpc":"2.0", "result":{ "items":[ {"blockHash":"ca9179c4e02017adcd538efb3874b1857b4121814c7d15ec15f8fc0a93481466","transactions":[{}]}, {"blockHash":"ca9179c4e02017adcd538efb3874b1857b4121814c7d15ec15f8fc0a93481466","transactions":[{}]} ] } }
Parameter Description

firstBlockIndex

The first block to start from

blockCount

The number of blocks to analyse for transactions

getTransaction

Returns the details of a given transaction. curl -d '{"method":"getTransaction","params": {"transactionHash":"9fb36d4bb905ef360c877ce8eba9c9dafc81da27cae85bd4727af46c5ba75ef7"},"jsonrpc": "2.0", "id": "1"}' http://username:[email protected]:8070/json_rpc

Expected output:

{ "id":"1", "jsonrpc":"2.0", "result":{ "transaction":{ "amount":-1000, "blockIndex":4294967295, "extra":"015371f8a3cdae5b7ec5fd8e79e3f1d524f8f4d9d884d6c74b81d63e4076b04b1201", "fee":0, "isBase":false, "paymentId":"", "state":2, "timestamp":0, "transactionHash":"9fb36d4bb905ef360c877ce8eba9c9dafc81da27cae85bd4727af46c5ba75ef7", "transfers":[ { "address":"Xun3qFybMCTcqzexD68QMjDoHUDUqUCWEJ82svTJ5vtbYF652s7o3njYe2AvyWtSL2iiiELby9mGH6dkQZryga4P4fVVUmGVMk", "amount":1000, "type":0 }, { "address":"Xun3ZtBPE7eYvz1Uokg9zg9m8UJsYdWFyEFT6Mmk4snXgMeaSfAQRGKhHPSR7X6nPG5DVpjrpNJ2Jg7Ej4DV3xgL5PEsCMBnGV", "amount":899000, "type":2 }, { "address":"Xun3ZtBPE7eYvz1Uokg9zg9m8UJsYdWFyEFT6Mmk4snXgMeaSfAQRGKhHPSR7X6nPG5DVpjrpNJ2Jg7Ej4DV3xgL5PEsCMBnGV", "amount":-900000, "type":0 } ], "unlockTime":0 } } }
Parameter Description

transactionHash

The hash of the transaction you are interested in

sendTransaction

Sends an ammount of Xun from one address to an other. curl -d '{ "method":"sendTransaction", "params": { "addresses":["Xun3ZtBPE7e..."], "anonymity": 2, "fee": 10000, "transfers":[ { "amount":900000, "address":"Xun3qFybMCT..." } ] }, "jsonrpc": "2.0", "id": "1" }' http://username:[email protected]:8070/json_rpc

Expected output:

{ "id":"1", "jsonrpc":"2.0", "result":{ "transactionhash":"a599cbd0616c60e0ea75aaaac1c79dd8ba23e1ab50eeed6fc48206ec13fd8828..." } }
Parameter Description

addresses

Array of Addresses, Addresses which should be charged. Be careful, If you didn't specify addresses the daemon can charge all wallets to collets needed amount.

anonymity

The anonymity level of the transaction

fee

The fee that you are willing to pay for the transaction

transfers

Array of Arrays, Contains couples [ammount, address] of all the transfers you want to execute within the transaction

reset

Re-sync cointainer starting from 0 block.

save

Save current container state. Do it before making reserve copies or reboots.


Didn't find an answer to your question?