Dynex Walletd RPC

Dynex Walletd RPC

Dynex Walletd RPC

Setting up the DynexD Wallet Service

1) To create the main wallet container file, you need to first generate a container (this command will generate a container file called “wallet.bin”:

./walletd -w wallet.bin -g --local

Then enter a strong password when prompted. Once you entered the password, you will find the container file “wallet.bin” in your directory. Walletd will quit after generating the wallet.

2) To start the walletd service, use the following command:

./walletd -w wallet.bin -p PASSWORD --local

After that, you can interact with the wallet through RPC commands. Please note that the parameter “–local” causes the walletd service to also start a full Dynex node, so there is no need to connect to a separate dynexd node.

Verify and Check the Status of Walletd

curl -d '{"jsonrpc":"2.0","id":1,"method":"getStatus","params":{}}' http://localhost:8070/json_rpc

Returns:

{"id":1,"jsonrpc":"2.0","result":{"blockCount":93472,"knownBlockCount":93472,"lastBlockHash":"b36f46e9c3cd58bd7a34251113e3b7a095c3fdaa53448e7e0f72de045fd9af12","localDaemonBlockCount":93472,"minimalFee":1000000,"peerCount":8,"version":"2.2.0-20221217 (#mandatory)"}}


Retrieve the Wallet Address

curl -d '{"jsonrpc":"2.0","id":1,"method":"getAddresses","params":{}}' http://localhost:8070/json_rpc

Returns:

{"id":1,"jsonrpc":"2.0","result":{"addresses":["XwogxAFZ9kzE5N7CmZPLASeexLd2iakcz5BBqAbbfZbeg1GwASnG5XTV6nfR6RbTVuXHL6cUZmxzEMW72tmWZmzT1FnokQxGF"]}}


Retrieve Balance of a Wallet

curl -d '{"jsonrpc":"2.0","id":1,"method":"getBalance","params":{}}' http://localhost:8070/json_rpc

Returns:

{"id":1,"jsonrpc":"2.0","result":{"availableBalance":0,"lockedAmount":10000000000}} NOTES: - DNX are locked for a confirmation time of 8 blocks. until then, every received and sent DNX is in status "locked". - After 8 confirmations, the locked amount becomes available. - All amounts have 9 digits precision. For example, 10000000000 => 10.000000000 DNX


Retrieve Transactions in the Wallet

The following command retrieves all transactions in this wallet. You can also specify a block range to query from, starting from firstBlockIndex for blockCount numbers of blocks. It is also possible to query transactions based on paymentID (which must be a 64 char hex string) by adding the parameter “paymentId”:"<VALID_PAYMENT_ID>" to the command. This filters all transactions with that payment ID.

curl -d '{"jsonrpc":"2.0","id":1,"method":"getTransactions","params":{"firstBlockIndex":0,"blockCount":100000000}}' http://localhost:8070/json_rpc

Returns:

{"id":1,"jsonrpc":"2.0","result":{"items":[{"blockHash":"d17ac30b4b79020af2778df9c15c0f8c154d6538e326ce789db0761152d6de61","transactions":[{"amount":10000000000,"blockIndex":93476,"confirmations":7,"extra":"01b5680267658864fed5a2e1e15097771d4b540210937d70f591c61f363c06e21c","fee":100000,"isBase":false,"paymentId":"","state":0,"timestamp":1674041846,"transactionHash":"a5ea8d59c5950ba637661fa26a06ed13b2c19607105e4e8f1547ef512d3f85c0","transfers":[{"address":"XwogxAFZ9kzE5N7CmZPLASeexLd2iakcz5BBqAbbfZbeg1GwASnG5XTV6nfR6RbTVuXHL6cUZmxzEMW72tmWZmzT1FnokQxGF","amount":10000000000,"type":0},{"address":"","amount":-334789327964,"type":0},{"address":"","amount":324789227964,"type":0}],"unlockTime":0}]}]}}

It returns an array counting block_hash as well as all transactions within, including timestamps, addresses amounts, paymentID and unlockTime (Height of the block when the transaction is going to be available for spending). If the amount has been spent, it is a negative number, if it has been received, it is a positive number.


Retrieve Transaction Details by Transaction Hash

curl -d '{"jsonrpc":"2.0","id":1,"method":"getTransaction","params":{"transactionHash":"a5ea8d59c5950ba637661fa26a06ed13b2c19607105e4e8f1547ef512d3f85c0"}}' http://localhost:8070/json_rpc

Returns:

{"id":1,"jsonrpc":"2.0","result":{"transaction":{"amount":10000000000,"blockIndex":93476,"confirmations":10,"extra":"01b5680267658864fed5a2e1e15097771d4b540210937d70f591c61f363c06e21c","fee":100000,"isBase":false,"paymentId":"","state":0,"timestamp":1674041846,"transactionHash":"a5ea8d59c5950ba637661fa26a06ed13b2c19607105e4e8f1547ef512d3f85c0","transfers":[{"address":"XwogxAFZ9kzE5N7CmZPLASeexLd2iakcz5BBqAbbfZbeg1GwASnG5XTV6nfR6RbTVuXHL6cUZmxzEMW72tmWZmzT1FnokQxGF","amount":10000000000,"type":0},{"address":"","amount":-334789327964,"type":0},{"address":"","amount":324789227964,"type":0}],"unlockTime":0}}}


Send DNX to an Address

To send DNX from your walletd to one ore more recipients, use the following command. Please note that amounts have to be specified in nanoDNX, whereas 1,000,000,000 nanoDNX = 1 DNX. This example transfers the amount of 1 DNX:

curl -X POST -i -H "Accept: application/json" -d '{"params": {"unlockTime":0, "anonymity":0, "fee":1000000,"transfers":[{"amount":1000000000, "address":"<DESTINATION_ADDRESS>"}]}, "jsonrpc": "2.0", "id": "test","method":"sendTransaction"}' http://localhost:8070/json_rpc

Returns:

{"id":"test","jsonrpc":"2.0","result":{"transactionHash":"7587a5e52834fd1f8b805d33e799e49138ce31773cf982d2b0d947102a2b1c5c","transactionSecretKey":"defbc795aa24ca7e2ed1cf0b51f421c445f6d9a48da20bd665ad47dae29aa50b"}}

NOTE: The json command will return “error” with a description if the wallet or the node didn’t accept the transfer.

(Optional) Transfer with Payment-ID (Memo):

curl -X POST -i -H "Accept: application/json" -d '{"params": {"unlockTime":0, "anonymity":0, "fee":1000000, "paymentId":"<VALID_PAYMENT_ID>", "transfers":[{"amount":1000000000, "address":"<DESTINATION_ADDRESS>"}]}, "jsonrpc": "2.0", "id": "test","method":"sendTransaction"}' http://localhost:8070/json_rpc

(Optional) Transfer from Sub-Address in Wallet Container:

curl -X POST -i -H "Accept: application/json" -d '{"params": {"addresses":["<SOURCE_ADDRESS>"], "changeAddress":"<SOURCE_ADDRESS", "unlockTime":0, "anonymity":0, "fee":1000000, "paymentId":"<VALID_PAYMENT_ID>", "transfers":[{"amount":1000000000, "address":"<DESTINATION_ADDRESS>"}]}, "jsonrpc": "2.0", "id": "test","method":"sendTransaction"}' http://localhost:8070/json_rpc


Complete List of all Available RPC Methods
  • Save

  • Reset

  • Export

  • CreateAddress

  • CreateAddressList

  • DeleteAddress

  • GetSpendKeys

  • GetBalance

  • GetBlockHashes

  • GetTransactionHashes

  • GetTransactions

  • GetUnconfirmedTransactionHashes

  • GetTransaction

  • GetTransactionSecretKey

  • GetTransactionProof

  • SendTransaction

  • CreateDelayedTransaction

  • GetDelayedTransactionHashes

  • DeleteDelayedTransaction

  • SendDelayedTransaction

  • GetViewKey

  • GetMnemonicSeed

  • GetStatus

  • GetAddresses

  • SendFusionTransaction

  • EstimateFusion

  • ValidateAddress

  • GetReserveProof

Details of parameters to submit can be found directly in the code.

PHP EXAMPLES

PLEASE NOTE THAT THESE EXAMPLES REQUIRE STARTING THE WALLETD SERVICE WITH AUTHORISATION KEYS:

./walletd --rpc-user <RPCUSER> --rpc-password <RPCPASSWORD> ...

EXAMPLE: Retrieve transaction for a given WALLET_ADDRESS within the blocks from start_block for block_count blocks

function get_transactions($WALLET_ADDRESS, $start_block, $block_count) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 5); //timeout in seconds
curl_setopt($ch, CURLOPT_URL, $WALLET_ENDPOINT.'json_rpc');
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST); curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"jsonrpc\":\"2.0\",\"id\":\"0\",\"method\":\"getTransactions\",\"params\":{\"addresses\":[\"".$WALLET_ADDRESS."\"],\"firstBlockIndex\":".$start_block.",\"blockCount\":".$block_count."}}");
$encoded = base64_encode("<RPCUSER>:<RPCPASSWORD>"); //only applicable if RPC authorisation is activated
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json','authorization: Basic '.$encoded)); //only applicable if RPC authorisation is activated curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
if (curl_errno($ch)) {
return "ERROR"; }
else {
$response_json = json_decode($response,true);
}
curl_close($ch);
}

EXAMPLE: display all transactions of wallet address:

echo '<div class="small" style="color: #ffffff; padding: 8px; font-size: 0.8rem;">LAST TRANSACTIONS</div>';
$txs = get_transactions(0, $BLOCK_HEIGHT);
$txs = $txs['result']['items'];
echo '<table class="table table-dark small" style="background-color: #0d0d0d; border-radius: 15px; color: white;">';
echo '<th class="small">DATE</th>';
echo '<th class="small" style="text-align: right;">CONF</th>';
echo '<th class="small" style="text-align: right;">FEE</th>';
echo '<th class="small" style="text-align: right;">AMOUNT</th>'; $txcount = 0;
$i=count($txs)-1;
while($i>=0 ) {
$block = $txs[$i]; $j = 0;
while ($j < count($block['transactions'])) {
$transactions = $block['transactions'][$j];
$k = 0;
$transaction_amount = 0;
while ($k < count($transactions['transfers'])) {
$transfer = $transactions['transfers'][$k];
$transfer_address = $transfer['address'];
if ($transfer_address == $WALLET_ADDRESS) {
$amount = intval($transfer['amount'])/1000000000;
$transaction_amount = $transaction_amount + $amount;
}
$k = $k + 1;
}
echo '<tr style="color: #afafaf;">';
$timestamp = gmdate("Y-m-d\TH:i:s\Z", $transactions['timestamp']);
$timestr = substr($timestamp,2);
$timestr = substr($timestr, 0, -1);
$timestr = substr($timestr, 0,8)." ".substr($timestr, 9);
$txhash = $transactions['transactionHash'];
echo '<td class="small" style="white-space: nowrap;"><a href="https://dynex.dyndns.org/show_transaction.php?tx='.$txhash.'">'.$timestr.'</a></td>';
echo '<td class="small">'.$transactions['blockIndex'].'</td>';
// are we still locked?
$conf_locked = '';
if ($transactions['confirmations']<9) {$conf_locked='<i class="text-warning fa-solid fa-lock"></i> ';}
if ($transactions['confirmations']<=100) { echo '<td class="small" style="text-align: right;">'.$conf_locked.number_format($transactions['confirmations'],0,'.',',').'</td>'; } else { echo '<td class="small" style="text-align: right;">>100</td>'; }
if ($transaction_amount<0) { echo '<td class="small" style="text-align: right;">'.number_format(intval($transactions['fee'])/1000000000,3,'.',',').'</td>';
echo '<td class="small" style="text-align: right; color: silver;">'.number_format($transaction_amount,3,'.',',').'</td>'; } if ($transaction_amount==0) {
echo '<td class="small" style="text-align: right;">'.number_format(intval($transactions['fee'])/1000000000,3,'.',',').'</td>';
echo '<td class="small" style="text-align: right; color: white;">'.number_format($transaction_amount,3,'.',',').'</td>'; }
if ($transaction_amount>0) {
echo '<td class="small" style="text-align: right;">&nbsp;</td>';
echo '<td class="small" style="text-align: right; color: white;">+'.number_format($transaction_amount,3,'.',',').'</td>'; }
echo '</tr>'; $txcount = $txcount + 1;
echo '<tr><td class="small" colspan="4">'.$transactions['transactionHash'].'</td></tr>';
$j = $j + 1; }
$i = $i - 1; }
if ($txcount<=0) {
echo '<tr><td colspan=4 style="color: silver;">You have no transactions yet.</td></tr>';
}
echo '</table></div>';

EXAMPLE: create a wallet address

function create_address() {
$WALLET_ENDPOINT = "http://127.0.0.1:8070/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $WALLET_ENDPOINT.'json_rpc'); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"jsonrpc\":\"2.0\",\"id\":\"0\",\"method\":\"createAddress\",\"params\":{}}"); $encoded = base64_encode("<RPC_USERNAME>:<RPC_PASSWORD>");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json','authorization: Basic '.$encoded));
curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
if (curl_errno($ch)) { return "ERROR"; } else { $response_json = json_decode($response,true); }
curl_close($ch);
return $response_json;
}

EXAMPLE: send a transaction

/* curl -X POST -i -H "Accept: application/json" -d '{"params": {"unlockTime":0, "anonymity":0, "fee":1000000,"transfers":[{"amount":1000000000,"address":"XwnYXhWyhFKAn1LXuAu2YaPZfmTcmMTFK4q8JVkmyCs7hJYXz4ahN2> */ //amount in nanoDNX 1 DNX = 1000000000 nanoDNX(!)

function send_transaction($address, $amount, $paymentid) {
global $WALLET_ENDPOINT;
global $WALLET_ADDRESS;

//sanity checks:
if (!ctype_alnum($address)) { return "ERROR"; }
if ($paymentid!="") { if (!ctype_alnum($paymentid)) { return "ERROR"; } }
if (!is_numeric($amount)) { return "ERROR"; }

$params = '"params": {"addresses":["'.$WALLET_ADDRESS.'"], "changeAddress":"'.$WALLET_ADDRESS.'", "paymentId":"'.$paymentid.'", "unlockTime":0, "anonymity":0, "fee":1000000,"transfers":[{"amount":'.> $WALLET_ENDPOINT = "http://127.0.0.1:8070/";

$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $WALLET_ENDPOINT.'json_rpc');
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"jsonrpc\":\"2.0\",\"id\":\"0\",\"method\":\"sendTransaction\",".$params."}");
$encoded = base64_encode("<RPC_USERNAME>:<RPC_PASSWORD>");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json','authorization: Basic '.$encoded));
curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
$response_json = json_decode($response,true);
if (isset($response_json['error'])) {
return "ERROR"; }
else {
$response_json = json_decode($response,true);
}
curl_close($ch);
return $response_json;
}

EXAMPLE: get memory pool transactions (= transactions still in memory pool which are not yet confirmed)

function get_unconfirmed_transactionHashes() {
global $WALLET_ENDPOINT;
global $WALLET_ADDRESS;

if ($WALLET_ADDRESS!='') {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $WALLET_ENDPOINT.'json_rpc');
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST); curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"jsonrpc\":\"2.0\",\"id\":\"0\",\"method\":\"getUnconfirmedTransactionHashes\",\"params\":{\"address\":\"".$WALLET_ADDRESS."\"}}");
$encoded = base64_encode("<RPC_USERNAME>:<RPC_PASSWORD>");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json','authorization: Basic '.$encoded));
curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
if (curl_errno($ch)) {
return "ERROR"; }
else {
$response_json = json_decode($response,true);
}
curl_close($ch);
return $response_json;
} else {
return '';
}
}

Setting up the DynexD Wallet Service

1) To create the main wallet container file, you need to first generate a container (this command will generate a container file called “wallet.bin”:

./walletd -w wallet.bin -g --local

Then enter a strong password when prompted. Once you entered the password, you will find the container file “wallet.bin” in your directory. Walletd will quit after generating the wallet.

2) To start the walletd service, use the following command:

./walletd -w wallet.bin -p PASSWORD --local

After that, you can interact with the wallet through RPC commands. Please note that the parameter “–local” causes the walletd service to also start a full Dynex node, so there is no need to connect to a separate dynexd node.

Verify and Check the Status of Walletd

curl -d '{"jsonrpc":"2.0","id":1,"method":"getStatus","params":{}}' http://localhost:8070/json_rpc

Returns:

{"id":1,"jsonrpc":"2.0","result":{"blockCount":93472,"knownBlockCount":93472,"lastBlockHash":"b36f46e9c3cd58bd7a34251113e3b7a095c3fdaa53448e7e0f72de045fd9af12","localDaemonBlockCount":93472,"minimalFee":1000000,"peerCount":8,"version":"2.2.0-20221217 (#mandatory)"}}


Retrieve the Wallet Address

curl -d '{"jsonrpc":"2.0","id":1,"method":"getAddresses","params":{}}' http://localhost:8070/json_rpc

Returns:

{"id":1,"jsonrpc":"2.0","result":{"addresses":["XwogxAFZ9kzE5N7CmZPLASeexLd2iakcz5BBqAbbfZbeg1GwASnG5XTV6nfR6RbTVuXHL6cUZmxzEMW72tmWZmzT1FnokQxGF"]}}


Retrieve Balance of a Wallet

curl -d '{"jsonrpc":"2.0","id":1,"method":"getBalance","params":{}}' http://localhost:8070/json_rpc

Returns:

{"id":1,"jsonrpc":"2.0","result":{"availableBalance":0,"lockedAmount":10000000000}} NOTES: - DNX are locked for a confirmation time of 8 blocks. until then, every received and sent DNX is in status "locked". - After 8 confirmations, the locked amount becomes available. - All amounts have 9 digits precision. For example, 10000000000 => 10.000000000 DNX


Retrieve Transactions in the Wallet

The following command retrieves all transactions in this wallet. You can also specify a block range to query from, starting from firstBlockIndex for blockCount numbers of blocks. It is also possible to query transactions based on paymentID (which must be a 64 char hex string) by adding the parameter “paymentId”:"<VALID_PAYMENT_ID>" to the command. This filters all transactions with that payment ID.

curl -d '{"jsonrpc":"2.0","id":1,"method":"getTransactions","params":{"firstBlockIndex":0,"blockCount":100000000}}' http://localhost:8070/json_rpc

Returns:

{"id":1,"jsonrpc":"2.0","result":{"items":[{"blockHash":"d17ac30b4b79020af2778df9c15c0f8c154d6538e326ce789db0761152d6de61","transactions":[{"amount":10000000000,"blockIndex":93476,"confirmations":7,"extra":"01b5680267658864fed5a2e1e15097771d4b540210937d70f591c61f363c06e21c","fee":100000,"isBase":false,"paymentId":"","state":0,"timestamp":1674041846,"transactionHash":"a5ea8d59c5950ba637661fa26a06ed13b2c19607105e4e8f1547ef512d3f85c0","transfers":[{"address":"XwogxAFZ9kzE5N7CmZPLASeexLd2iakcz5BBqAbbfZbeg1GwASnG5XTV6nfR6RbTVuXHL6cUZmxzEMW72tmWZmzT1FnokQxGF","amount":10000000000,"type":0},{"address":"","amount":-334789327964,"type":0},{"address":"","amount":324789227964,"type":0}],"unlockTime":0}]}]}}

It returns an array counting block_hash as well as all transactions within, including timestamps, addresses amounts, paymentID and unlockTime (Height of the block when the transaction is going to be available for spending). If the amount has been spent, it is a negative number, if it has been received, it is a positive number.


Retrieve Transaction Details by Transaction Hash

curl -d '{"jsonrpc":"2.0","id":1,"method":"getTransaction","params":{"transactionHash":"a5ea8d59c5950ba637661fa26a06ed13b2c19607105e4e8f1547ef512d3f85c0"}}' http://localhost:8070/json_rpc

Returns:

{"id":1,"jsonrpc":"2.0","result":{"transaction":{"amount":10000000000,"blockIndex":93476,"confirmations":10,"extra":"01b5680267658864fed5a2e1e15097771d4b540210937d70f591c61f363c06e21c","fee":100000,"isBase":false,"paymentId":"","state":0,"timestamp":1674041846,"transactionHash":"a5ea8d59c5950ba637661fa26a06ed13b2c19607105e4e8f1547ef512d3f85c0","transfers":[{"address":"XwogxAFZ9kzE5N7CmZPLASeexLd2iakcz5BBqAbbfZbeg1GwASnG5XTV6nfR6RbTVuXHL6cUZmxzEMW72tmWZmzT1FnokQxGF","amount":10000000000,"type":0},{"address":"","amount":-334789327964,"type":0},{"address":"","amount":324789227964,"type":0}],"unlockTime":0}}}


Send DNX to an Address

To send DNX from your walletd to one ore more recipients, use the following command. Please note that amounts have to be specified in nanoDNX, whereas 1,000,000,000 nanoDNX = 1 DNX. This example transfers the amount of 1 DNX:

curl -X POST -i -H "Accept: application/json" -d '{"params": {"unlockTime":0, "anonymity":0, "fee":1000000,"transfers":[{"amount":1000000000, "address":"<DESTINATION_ADDRESS>"}]}, "jsonrpc": "2.0", "id": "test","method":"sendTransaction"}' http://localhost:8070/json_rpc

Returns:

{"id":"test","jsonrpc":"2.0","result":{"transactionHash":"7587a5e52834fd1f8b805d33e799e49138ce31773cf982d2b0d947102a2b1c5c","transactionSecretKey":"defbc795aa24ca7e2ed1cf0b51f421c445f6d9a48da20bd665ad47dae29aa50b"}}

NOTE: The json command will return “error” with a description if the wallet or the node didn’t accept the transfer.

(Optional) Transfer with Payment-ID (Memo):

curl -X POST -i -H "Accept: application/json" -d '{"params": {"unlockTime":0, "anonymity":0, "fee":1000000, "paymentId":"<VALID_PAYMENT_ID>", "transfers":[{"amount":1000000000, "address":"<DESTINATION_ADDRESS>"}]}, "jsonrpc": "2.0", "id": "test","method":"sendTransaction"}' http://localhost:8070/json_rpc

(Optional) Transfer from Sub-Address in Wallet Container:

curl -X POST -i -H "Accept: application/json" -d '{"params": {"addresses":["<SOURCE_ADDRESS>"], "changeAddress":"<SOURCE_ADDRESS", "unlockTime":0, "anonymity":0, "fee":1000000, "paymentId":"<VALID_PAYMENT_ID>", "transfers":[{"amount":1000000000, "address":"<DESTINATION_ADDRESS>"}]}, "jsonrpc": "2.0", "id": "test","method":"sendTransaction"}' http://localhost:8070/json_rpc


Complete List of all Available RPC Methods
  • Save

  • Reset

  • Export

  • CreateAddress

  • CreateAddressList

  • DeleteAddress

  • GetSpendKeys

  • GetBalance

  • GetBlockHashes

  • GetTransactionHashes

  • GetTransactions

  • GetUnconfirmedTransactionHashes

  • GetTransaction

  • GetTransactionSecretKey

  • GetTransactionProof

  • SendTransaction

  • CreateDelayedTransaction

  • GetDelayedTransactionHashes

  • DeleteDelayedTransaction

  • SendDelayedTransaction

  • GetViewKey

  • GetMnemonicSeed

  • GetStatus

  • GetAddresses

  • SendFusionTransaction

  • EstimateFusion

  • ValidateAddress

  • GetReserveProof

Details of parameters to submit can be found directly in the code.

PHP EXAMPLES

PLEASE NOTE THAT THESE EXAMPLES REQUIRE STARTING THE WALLETD SERVICE WITH AUTHORISATION KEYS:

./walletd --rpc-user <RPCUSER> --rpc-password <RPCPASSWORD> ...

EXAMPLE: Retrieve transaction for a given WALLET_ADDRESS within the blocks from start_block for block_count blocks

function get_transactions($WALLET_ADDRESS, $start_block, $block_count) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 5); //timeout in seconds
curl_setopt($ch, CURLOPT_URL, $WALLET_ENDPOINT.'json_rpc');
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST); curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"jsonrpc\":\"2.0\",\"id\":\"0\",\"method\":\"getTransactions\",\"params\":{\"addresses\":[\"".$WALLET_ADDRESS."\"],\"firstBlockIndex\":".$start_block.",\"blockCount\":".$block_count."}}");
$encoded = base64_encode("<RPCUSER>:<RPCPASSWORD>"); //only applicable if RPC authorisation is activated
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json','authorization: Basic '.$encoded)); //only applicable if RPC authorisation is activated curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
if (curl_errno($ch)) {
return "ERROR"; }
else {
$response_json = json_decode($response,true);
}
curl_close($ch);
}

EXAMPLE: display all transactions of wallet address:

echo '<div class="small" style="color: #ffffff; padding: 8px; font-size: 0.8rem;">LAST TRANSACTIONS</div>';
$txs = get_transactions(0, $BLOCK_HEIGHT);
$txs = $txs['result']['items'];
echo '<table class="table table-dark small" style="background-color: #0d0d0d; border-radius: 15px; color: white;">';
echo '<th class="small">DATE</th>';
echo '<th class="small" style="text-align: right;">CONF</th>';
echo '<th class="small" style="text-align: right;">FEE</th>';
echo '<th class="small" style="text-align: right;">AMOUNT</th>'; $txcount = 0;
$i=count($txs)-1;
while($i>=0 ) {
$block = $txs[$i]; $j = 0;
while ($j < count($block['transactions'])) {
$transactions = $block['transactions'][$j];
$k = 0;
$transaction_amount = 0;
while ($k < count($transactions['transfers'])) {
$transfer = $transactions['transfers'][$k];
$transfer_address = $transfer['address'];
if ($transfer_address == $WALLET_ADDRESS) {
$amount = intval($transfer['amount'])/1000000000;
$transaction_amount = $transaction_amount + $amount;
}
$k = $k + 1;
}
echo '<tr style="color: #afafaf;">';
$timestamp = gmdate("Y-m-d\TH:i:s\Z", $transactions['timestamp']);
$timestr = substr($timestamp,2);
$timestr = substr($timestr, 0, -1);
$timestr = substr($timestr, 0,8)." ".substr($timestr, 9);
$txhash = $transactions['transactionHash'];
echo '<td class="small" style="white-space: nowrap;"><a href="https://dynex.dyndns.org/show_transaction.php?tx='.$txhash.'">'.$timestr.'</a></td>';
echo '<td class="small">'.$transactions['blockIndex'].'</td>';
// are we still locked?
$conf_locked = '';
if ($transactions['confirmations']<9) {$conf_locked='<i class="text-warning fa-solid fa-lock"></i> ';}
if ($transactions['confirmations']<=100) { echo '<td class="small" style="text-align: right;">'.$conf_locked.number_format($transactions['confirmations'],0,'.',',').'</td>'; } else { echo '<td class="small" style="text-align: right;">>100</td>'; }
if ($transaction_amount<0) { echo '<td class="small" style="text-align: right;">'.number_format(intval($transactions['fee'])/1000000000,3,'.',',').'</td>';
echo '<td class="small" style="text-align: right; color: silver;">'.number_format($transaction_amount,3,'.',',').'</td>'; } if ($transaction_amount==0) {
echo '<td class="small" style="text-align: right;">'.number_format(intval($transactions['fee'])/1000000000,3,'.',',').'</td>';
echo '<td class="small" style="text-align: right; color: white;">'.number_format($transaction_amount,3,'.',',').'</td>'; }
if ($transaction_amount>0) {
echo '<td class="small" style="text-align: right;">&nbsp;</td>';
echo '<td class="small" style="text-align: right; color: white;">+'.number_format($transaction_amount,3,'.',',').'</td>'; }
echo '</tr>'; $txcount = $txcount + 1;
echo '<tr><td class="small" colspan="4">'.$transactions['transactionHash'].'</td></tr>';
$j = $j + 1; }
$i = $i - 1; }
if ($txcount<=0) {
echo '<tr><td colspan=4 style="color: silver;">You have no transactions yet.</td></tr>';
}
echo '</table></div>';

EXAMPLE: create a wallet address

function create_address() {
$WALLET_ENDPOINT = "http://127.0.0.1:8070/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $WALLET_ENDPOINT.'json_rpc'); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"jsonrpc\":\"2.0\",\"id\":\"0\",\"method\":\"createAddress\",\"params\":{}}"); $encoded = base64_encode("<RPC_USERNAME>:<RPC_PASSWORD>");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json','authorization: Basic '.$encoded));
curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
if (curl_errno($ch)) { return "ERROR"; } else { $response_json = json_decode($response,true); }
curl_close($ch);
return $response_json;
}

EXAMPLE: send a transaction

/* curl -X POST -i -H "Accept: application/json" -d '{"params": {"unlockTime":0, "anonymity":0, "fee":1000000,"transfers":[{"amount":1000000000,"address":"XwnYXhWyhFKAn1LXuAu2YaPZfmTcmMTFK4q8JVkmyCs7hJYXz4ahN2> */ //amount in nanoDNX 1 DNX = 1000000000 nanoDNX(!)

function send_transaction($address, $amount, $paymentid) {
global $WALLET_ENDPOINT;
global $WALLET_ADDRESS;

//sanity checks:
if (!ctype_alnum($address)) { return "ERROR"; }
if ($paymentid!="") { if (!ctype_alnum($paymentid)) { return "ERROR"; } }
if (!is_numeric($amount)) { return "ERROR"; }

$params = '"params": {"addresses":["'.$WALLET_ADDRESS.'"], "changeAddress":"'.$WALLET_ADDRESS.'", "paymentId":"'.$paymentid.'", "unlockTime":0, "anonymity":0, "fee":1000000,"transfers":[{"amount":'.> $WALLET_ENDPOINT = "http://127.0.0.1:8070/";

$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $WALLET_ENDPOINT.'json_rpc');
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"jsonrpc\":\"2.0\",\"id\":\"0\",\"method\":\"sendTransaction\",".$params."}");
$encoded = base64_encode("<RPC_USERNAME>:<RPC_PASSWORD>");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json','authorization: Basic '.$encoded));
curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
$response_json = json_decode($response,true);
if (isset($response_json['error'])) {
return "ERROR"; }
else {
$response_json = json_decode($response,true);
}
curl_close($ch);
return $response_json;
}

EXAMPLE: get memory pool transactions (= transactions still in memory pool which are not yet confirmed)

function get_unconfirmed_transactionHashes() {
global $WALLET_ENDPOINT;
global $WALLET_ADDRESS;

if ($WALLET_ADDRESS!='') {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $WALLET_ENDPOINT.'json_rpc');
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST); curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"jsonrpc\":\"2.0\",\"id\":\"0\",\"method\":\"getUnconfirmedTransactionHashes\",\"params\":{\"address\":\"".$WALLET_ADDRESS."\"}}");
$encoded = base64_encode("<RPC_USERNAME>:<RPC_PASSWORD>");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json','authorization: Basic '.$encoded));
curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
if (curl_errno($ch)) {
return "ERROR"; }
else {
$response_json = json_decode($response,true);
}
curl_close($ch);
return $response_json;
} else {
return '';
}
}

Setting up the DynexD Wallet Service

1) To create the main wallet container file, you need to first generate a container (this command will generate a container file called “wallet.bin”:

./walletd -w wallet.bin -g --local

Then enter a strong password when prompted. Once you entered the password, you will find the container file “wallet.bin” in your directory. Walletd will quit after generating the wallet.

2) To start the walletd service, use the following command:

./walletd -w wallet.bin -p PASSWORD --local

After that, you can interact with the wallet through RPC commands. Please note that the parameter “–local” causes the walletd service to also start a full Dynex node, so there is no need to connect to a separate dynexd node.

Verify and Check the Status of Walletd

curl -d '{"jsonrpc":"2.0","id":1,"method":"getStatus","params":{}}' http://localhost:8070/json_rpc

Returns:

{"id":1,"jsonrpc":"2.0","result":{"blockCount":93472,"knownBlockCount":93472,"lastBlockHash":"b36f46e9c3cd58bd7a34251113e3b7a095c3fdaa53448e7e0f72de045fd9af12","localDaemonBlockCount":93472,"minimalFee":1000000,"peerCount":8,"version":"2.2.0-20221217 (#mandatory)"}}


Retrieve the Wallet Address

curl -d '{"jsonrpc":"2.0","id":1,"method":"getAddresses","params":{}}' http://localhost:8070/json_rpc

Returns:

{"id":1,"jsonrpc":"2.0","result":{"addresses":["XwogxAFZ9kzE5N7CmZPLASeexLd2iakcz5BBqAbbfZbeg1GwASnG5XTV6nfR6RbTVuXHL6cUZmxzEMW72tmWZmzT1FnokQxGF"]}}


Retrieve Balance of a Wallet

curl -d '{"jsonrpc":"2.0","id":1,"method":"getBalance","params":{}}' http://localhost:8070/json_rpc

Returns:

{"id":1,"jsonrpc":"2.0","result":{"availableBalance":0,"lockedAmount":10000000000}} NOTES: - DNX are locked for a confirmation time of 8 blocks. until then, every received and sent DNX is in status "locked". - After 8 confirmations, the locked amount becomes available. - All amounts have 9 digits precision. For example, 10000000000 => 10.000000000 DNX


Retrieve Transactions in the Wallet

The following command retrieves all transactions in this wallet. You can also specify a block range to query from, starting from firstBlockIndex for blockCount numbers of blocks. It is also possible to query transactions based on paymentID (which must be a 64 char hex string) by adding the parameter “paymentId”:"<VALID_PAYMENT_ID>" to the command. This filters all transactions with that payment ID.

curl -d '{"jsonrpc":"2.0","id":1,"method":"getTransactions","params":{"firstBlockIndex":0,"blockCount":100000000}}' http://localhost:8070/json_rpc

Returns:

{"id":1,"jsonrpc":"2.0","result":{"items":[{"blockHash":"d17ac30b4b79020af2778df9c15c0f8c154d6538e326ce789db0761152d6de61","transactions":[{"amount":10000000000,"blockIndex":93476,"confirmations":7,"extra":"01b5680267658864fed5a2e1e15097771d4b540210937d70f591c61f363c06e21c","fee":100000,"isBase":false,"paymentId":"","state":0,"timestamp":1674041846,"transactionHash":"a5ea8d59c5950ba637661fa26a06ed13b2c19607105e4e8f1547ef512d3f85c0","transfers":[{"address":"XwogxAFZ9kzE5N7CmZPLASeexLd2iakcz5BBqAbbfZbeg1GwASnG5XTV6nfR6RbTVuXHL6cUZmxzEMW72tmWZmzT1FnokQxGF","amount":10000000000,"type":0},{"address":"","amount":-334789327964,"type":0},{"address":"","amount":324789227964,"type":0}],"unlockTime":0}]}]}}

It returns an array counting block_hash as well as all transactions within, including timestamps, addresses amounts, paymentID and unlockTime (Height of the block when the transaction is going to be available for spending). If the amount has been spent, it is a negative number, if it has been received, it is a positive number.


Retrieve Transaction Details by Transaction Hash

curl -d '{"jsonrpc":"2.0","id":1,"method":"getTransaction","params":{"transactionHash":"a5ea8d59c5950ba637661fa26a06ed13b2c19607105e4e8f1547ef512d3f85c0"}}' http://localhost:8070/json_rpc

Returns:

{"id":1,"jsonrpc":"2.0","result":{"transaction":{"amount":10000000000,"blockIndex":93476,"confirmations":10,"extra":"01b5680267658864fed5a2e1e15097771d4b540210937d70f591c61f363c06e21c","fee":100000,"isBase":false,"paymentId":"","state":0,"timestamp":1674041846,"transactionHash":"a5ea8d59c5950ba637661fa26a06ed13b2c19607105e4e8f1547ef512d3f85c0","transfers":[{"address":"XwogxAFZ9kzE5N7CmZPLASeexLd2iakcz5BBqAbbfZbeg1GwASnG5XTV6nfR6RbTVuXHL6cUZmxzEMW72tmWZmzT1FnokQxGF","amount":10000000000,"type":0},{"address":"","amount":-334789327964,"type":0},{"address":"","amount":324789227964,"type":0}],"unlockTime":0}}}


Send DNX to an Address

To send DNX from your walletd to one ore more recipients, use the following command. Please note that amounts have to be specified in nanoDNX, whereas 1,000,000,000 nanoDNX = 1 DNX. This example transfers the amount of 1 DNX:

curl -X POST -i -H "Accept: application/json" -d '{"params": {"unlockTime":0, "anonymity":0, "fee":1000000,"transfers":[{"amount":1000000000, "address":"<DESTINATION_ADDRESS>"}]}, "jsonrpc": "2.0", "id": "test","method":"sendTransaction"}' http://localhost:8070/json_rpc

Returns:

{"id":"test","jsonrpc":"2.0","result":{"transactionHash":"7587a5e52834fd1f8b805d33e799e49138ce31773cf982d2b0d947102a2b1c5c","transactionSecretKey":"defbc795aa24ca7e2ed1cf0b51f421c445f6d9a48da20bd665ad47dae29aa50b"}}

NOTE: The json command will return “error” with a description if the wallet or the node didn’t accept the transfer.

(Optional) Transfer with Payment-ID (Memo):

curl -X POST -i -H "Accept: application/json" -d '{"params": {"unlockTime":0, "anonymity":0, "fee":1000000, "paymentId":"<VALID_PAYMENT_ID>", "transfers":[{"amount":1000000000, "address":"<DESTINATION_ADDRESS>"}]}, "jsonrpc": "2.0", "id": "test","method":"sendTransaction"}' http://localhost:8070/json_rpc

(Optional) Transfer from Sub-Address in Wallet Container:

curl -X POST -i -H "Accept: application/json" -d '{"params": {"addresses":["<SOURCE_ADDRESS>"], "changeAddress":"<SOURCE_ADDRESS", "unlockTime":0, "anonymity":0, "fee":1000000, "paymentId":"<VALID_PAYMENT_ID>", "transfers":[{"amount":1000000000, "address":"<DESTINATION_ADDRESS>"}]}, "jsonrpc": "2.0", "id": "test","method":"sendTransaction"}' http://localhost:8070/json_rpc


Complete List of all Available RPC Methods
  • Save

  • Reset

  • Export

  • CreateAddress

  • CreateAddressList

  • DeleteAddress

  • GetSpendKeys

  • GetBalance

  • GetBlockHashes

  • GetTransactionHashes

  • GetTransactions

  • GetUnconfirmedTransactionHashes

  • GetTransaction

  • GetTransactionSecretKey

  • GetTransactionProof

  • SendTransaction

  • CreateDelayedTransaction

  • GetDelayedTransactionHashes

  • DeleteDelayedTransaction

  • SendDelayedTransaction

  • GetViewKey

  • GetMnemonicSeed

  • GetStatus

  • GetAddresses

  • SendFusionTransaction

  • EstimateFusion

  • ValidateAddress

  • GetReserveProof

Details of parameters to submit can be found directly in the code.

PHP EXAMPLES

PLEASE NOTE THAT THESE EXAMPLES REQUIRE STARTING THE WALLETD SERVICE WITH AUTHORISATION KEYS:

./walletd --rpc-user <RPCUSER> --rpc-password <RPCPASSWORD> ...

EXAMPLE: Retrieve transaction for a given WALLET_ADDRESS within the blocks from start_block for block_count blocks

function get_transactions($WALLET_ADDRESS, $start_block, $block_count) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 5); //timeout in seconds
curl_setopt($ch, CURLOPT_URL, $WALLET_ENDPOINT.'json_rpc');
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST); curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"jsonrpc\":\"2.0\",\"id\":\"0\",\"method\":\"getTransactions\",\"params\":{\"addresses\":[\"".$WALLET_ADDRESS."\"],\"firstBlockIndex\":".$start_block.",\"blockCount\":".$block_count."}}");
$encoded = base64_encode("<RPCUSER>:<RPCPASSWORD>"); //only applicable if RPC authorisation is activated
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json','authorization: Basic '.$encoded)); //only applicable if RPC authorisation is activated curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
if (curl_errno($ch)) {
return "ERROR"; }
else {
$response_json = json_decode($response,true);
}
curl_close($ch);
}

EXAMPLE: display all transactions of wallet address:

echo '<div class="small" style="color: #ffffff; padding: 8px; font-size: 0.8rem;">LAST TRANSACTIONS</div>';
$txs = get_transactions(0, $BLOCK_HEIGHT);
$txs = $txs['result']['items'];
echo '<table class="table table-dark small" style="background-color: #0d0d0d; border-radius: 15px; color: white;">';
echo '<th class="small">DATE</th>';
echo '<th class="small" style="text-align: right;">CONF</th>';
echo '<th class="small" style="text-align: right;">FEE</th>';
echo '<th class="small" style="text-align: right;">AMOUNT</th>'; $txcount = 0;
$i=count($txs)-1;
while($i>=0 ) {
$block = $txs[$i]; $j = 0;
while ($j < count($block['transactions'])) {
$transactions = $block['transactions'][$j];
$k = 0;
$transaction_amount = 0;
while ($k < count($transactions['transfers'])) {
$transfer = $transactions['transfers'][$k];
$transfer_address = $transfer['address'];
if ($transfer_address == $WALLET_ADDRESS) {
$amount = intval($transfer['amount'])/1000000000;
$transaction_amount = $transaction_amount + $amount;
}
$k = $k + 1;
}
echo '<tr style="color: #afafaf;">';
$timestamp = gmdate("Y-m-d\TH:i:s\Z", $transactions['timestamp']);
$timestr = substr($timestamp,2);
$timestr = substr($timestr, 0, -1);
$timestr = substr($timestr, 0,8)." ".substr($timestr, 9);
$txhash = $transactions['transactionHash'];
echo '<td class="small" style="white-space: nowrap;"><a href="https://dynex.dyndns.org/show_transaction.php?tx='.$txhash.'">'.$timestr.'</a></td>';
echo '<td class="small">'.$transactions['blockIndex'].'</td>';
// are we still locked?
$conf_locked = '';
if ($transactions['confirmations']<9) {$conf_locked='<i class="text-warning fa-solid fa-lock"></i> ';}
if ($transactions['confirmations']<=100) { echo '<td class="small" style="text-align: right;">'.$conf_locked.number_format($transactions['confirmations'],0,'.',',').'</td>'; } else { echo '<td class="small" style="text-align: right;">>100</td>'; }
if ($transaction_amount<0) { echo '<td class="small" style="text-align: right;">'.number_format(intval($transactions['fee'])/1000000000,3,'.',',').'</td>';
echo '<td class="small" style="text-align: right; color: silver;">'.number_format($transaction_amount,3,'.',',').'</td>'; } if ($transaction_amount==0) {
echo '<td class="small" style="text-align: right;">'.number_format(intval($transactions['fee'])/1000000000,3,'.',',').'</td>';
echo '<td class="small" style="text-align: right; color: white;">'.number_format($transaction_amount,3,'.',',').'</td>'; }
if ($transaction_amount>0) {
echo '<td class="small" style="text-align: right;">&nbsp;</td>';
echo '<td class="small" style="text-align: right; color: white;">+'.number_format($transaction_amount,3,'.',',').'</td>'; }
echo '</tr>'; $txcount = $txcount + 1;
echo '<tr><td class="small" colspan="4">'.$transactions['transactionHash'].'</td></tr>';
$j = $j + 1; }
$i = $i - 1; }
if ($txcount<=0) {
echo '<tr><td colspan=4 style="color: silver;">You have no transactions yet.</td></tr>';
}
echo '</table></div>';

EXAMPLE: create a wallet address

function create_address() {
$WALLET_ENDPOINT = "http://127.0.0.1:8070/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $WALLET_ENDPOINT.'json_rpc'); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"jsonrpc\":\"2.0\",\"id\":\"0\",\"method\":\"createAddress\",\"params\":{}}"); $encoded = base64_encode("<RPC_USERNAME>:<RPC_PASSWORD>");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json','authorization: Basic '.$encoded));
curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
if (curl_errno($ch)) { return "ERROR"; } else { $response_json = json_decode($response,true); }
curl_close($ch);
return $response_json;
}

EXAMPLE: send a transaction

/* curl -X POST -i -H "Accept: application/json" -d '{"params": {"unlockTime":0, "anonymity":0, "fee":1000000,"transfers":[{"amount":1000000000,"address":"XwnYXhWyhFKAn1LXuAu2YaPZfmTcmMTFK4q8JVkmyCs7hJYXz4ahN2> */ //amount in nanoDNX 1 DNX = 1000000000 nanoDNX(!)

function send_transaction($address, $amount, $paymentid) {
global $WALLET_ENDPOINT;
global $WALLET_ADDRESS;

//sanity checks:
if (!ctype_alnum($address)) { return "ERROR"; }
if ($paymentid!="") { if (!ctype_alnum($paymentid)) { return "ERROR"; } }
if (!is_numeric($amount)) { return "ERROR"; }

$params = '"params": {"addresses":["'.$WALLET_ADDRESS.'"], "changeAddress":"'.$WALLET_ADDRESS.'", "paymentId":"'.$paymentid.'", "unlockTime":0, "anonymity":0, "fee":1000000,"transfers":[{"amount":'.> $WALLET_ENDPOINT = "http://127.0.0.1:8070/";

$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $WALLET_ENDPOINT.'json_rpc');
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"jsonrpc\":\"2.0\",\"id\":\"0\",\"method\":\"sendTransaction\",".$params."}");
$encoded = base64_encode("<RPC_USERNAME>:<RPC_PASSWORD>");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json','authorization: Basic '.$encoded));
curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
$response_json = json_decode($response,true);
if (isset($response_json['error'])) {
return "ERROR"; }
else {
$response_json = json_decode($response,true);
}
curl_close($ch);
return $response_json;
}

EXAMPLE: get memory pool transactions (= transactions still in memory pool which are not yet confirmed)

function get_unconfirmed_transactionHashes() {
global $WALLET_ENDPOINT;
global $WALLET_ADDRESS;

if ($WALLET_ADDRESS!='') {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $WALLET_ENDPOINT.'json_rpc');
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST); curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"jsonrpc\":\"2.0\",\"id\":\"0\",\"method\":\"getUnconfirmedTransactionHashes\",\"params\":{\"address\":\"".$WALLET_ADDRESS."\"}}");
$encoded = base64_encode("<RPC_USERNAME>:<RPC_PASSWORD>");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json','authorization: Basic '.$encoded));
curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
if (curl_errno($ch)) {
return "ERROR"; }
else {
$response_json = json_decode($response,true);
}
curl_close($ch);
return $response_json;
} else {
return '';
}
}

Copyright © 2024 Dynex. All rights reserved.

Copyright © 2024 Dynex. All rights reserved.

Copyright © 2024 Dynex. All rights reserved.