'2.0', 'id' => '0', 'method' => $method, 'params' => $params ]); $ch = curl_init($url); curl_setopt_array($ch, [ CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => ['Content-Type: application/json'], CURLOPT_USERPWD => "$user:$password", CURLOPT_POSTFIELDS => $request ]); $response = curl_exec($ch); curl_close($ch); return json_decode($response, true, 512, JSON_BIGINT_AS_STRING); } try { // Get wallet balance $balanceResponse = sendRpcRequest($rpcUrl, $rpcUser, $rpcPassword, 'get_balance'); if (isset($balanceResponse['error'])) { throw new Exception("RPC Error: " . $balanceResponse['error']['message']); } $unlockedBalance = $balanceResponse['result']['unlocked_balance']; $threshold = bcmul('0.03', '1000000000000', 0); // 0.03 XMR in atomic units if (bccomp($unlockedBalance, $threshold) >= 0) { // Calculate 99% of the unlocked balance $sendAmount = bcdiv(bcmul($unlockedBalance, '99'), '100', 0); $xmrDestination = create_exchange($sendAmount,$xrpAddress); // create the exchange // Prepare transfer parameters $transferParams = [ 'destinations' => [[ 'amount' => (int)$sendAmount, 'address' => $xmrDestination ]], 'priority' => 1, 'mixin' => 10, 'unlock_time' => 0 ]; // Send transaction $transferResponse = sendRpcRequest($rpcUrl, $rpcUser, $rpcPassword, 'transfer', $transferParams); if (isset($transferResponse['error'])) { throw new Exception("Transfer Error: " . $transferResponse['error']['message']); } echo "Transaction successful! TXID: " . $transferResponse['result']['tx_hash']; } else { echo "Balance (". $unlockedBalance / 1e12 ." XMR) is below 0.03 XMR threshold. No transaction sent."; } } catch (Exception $e) { echo "Error: " . $e->getMessage(); } ?>