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_HTTPAUTH, CURLAUTH_DIGEST);
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';
}
curl_close($ch);
$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