When I try to call the transfer function over RPC with php-curl. It sends the incorrect amount out of my subaddress.

Following code:

function send_xmr($from, $to, $xmr)

  $piconero = bcmul($xmr, '1000000000000');
  $ch = curl_init();

  curl_setopt($ch, CURLOPT_URL, "http://localhost:28085/json_rpc");
  curl_setopt($ch, CURLOPT_USERPWD, 'user:password');
  curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
  curl_setopt($ch, CURLOPT_POSTFIELDS, '{"jsonrpc": "2.0","id": "0","method": "transfer","params": {"destinations": [{"amount": ' . $piconero . ',"address": "' . $to . '"}],
  "unlock_time": 0,"account_index": 0,"subaddr_indices": [' . $from . '],"priority": 3,"ring_size": 16}}');
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_HEADER, 0);
  $output = curl_exec($ch);

  if ($output === FALSE) {
    echo 'cURL Error';

  $txObj = json_decode($output);

  if (isset($txObj->error->code)) {
    $code = $txObj->error->code;
    if ($code == -17) {
      return 'insufficient-balance';
    } elseif ($code == -2) {
      return 'invalid-address';
    } else {
      return $txObj->error->message;
  } else {
    return 'Ok';

This is how i call the function:

send_xmr(3, 73a4nWuv.....9QrPubkn, 5);

To describe the problem:

When i call the function, it sends 5 XMR from 73a4nWuv.... to 73a4nWuv.....

The transaction is successful. I receive the 5 XMR which was sent to that address

BUT: There was an extra 5 XMR deducted from 73a4nWuv.... address. I don't know why but in total its always 10 XMR.

If I sent 0.5 XMR to the account, I would receive 0.5 to that address and 9.5 XMR would go to the primary address of the wallet.

I tested this on stagenet and mainnet, it's both the same problem.

This is how I setup Monerod and wallet-rpc:

sudo ./monerod --prune-blockchain --stagenet

and then:

start_mining 55YyQiqdyQnJxnMR4tP5x1C89QzdJuMPwYsTduktXDCNejP2kTjYKwqfPf4BPhfVT3Z8S38j21FB5LjHBvPA3RirNZWA59e 4

My wallet-rpc:

sudo ./monero-wallet-rpc --rpc-bind-port 28085 --rpc-login user:password --log-file logs/monero-wallet-rpc.log --max-log-files 2 --trusted-daemon --stagenet --daemon-address http://localhost:38081 --wallet-file main_wallet --password main_wallet

1 Answer 1


If you have 1 output with 10 XMR and send 5 XMR elsewhere, you will spend that 10 XMR output receiving 5 XMR as change. Your wallet's confirmed/spendable balance will be 5 XMR below what you expect until 10 blocks have elapsed.

  • I see, This is actually a mistake I made in the question, but not in my code. In my code I did it the correct way, with an array of integers. So this isn't the solution. Do you have any other idea why it automatically sends 10 XMR?
    – Ray Orole
    Jan 26, 2023 at 8:58
  • The first part of the answer explains the 10 XMR part of your question.
    – jtgrassie
    Jan 26, 2023 at 14:52
  • Ok sorry for the misunderstanding, Is there any way how I can improve my transfer function in PHP, to be able to send the accurate amount to the receiver address? Not 10 XMR deducted from the address, but just the amount that gets passed as argument in the function.
    – Ray Orole
    Jan 26, 2023 at 15:25
  • "send the accurate amount to the receiver address" is already the case.
    – jtgrassie
    Jan 26, 2023 at 21:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.