HOME INSTALL CONTACT

 

An App To Automatically Convert Mined XMR To XRP

Mine2XRP

Mine2XRP is an app to automatically convert rewards obtained from mining XMR to XRP. Many people, including myself, use their spare CPU and/or GPU power to mine the cryptocurrency XMR. XMR is the preferred cryptocurrency to mine for many people because it employs a proof-of-work algorithm called RandomX, which is ASIC-resistant, making it accessible to miners with regular computers (as opposed to only those with huge data centers that have a ton of computing power, or with specialized mining hardware). XMR also has a relatively low difficulty level of mining compared to other cryptocurrencies, which is another reason why many people prefer it to mining BTC or ETH. Unfortunately XRP cannot be mined.

The other thing that has recently occurred is a bull run for XRP, which many people believe is only just getting started due to many factors such 1) the SEC case against Ripple (the company that makes XRP) rapidly coming to an official end, and 2) the new administration's crypto policies, particularly for those made by US-based companies, which Ripple is. This has led to many people becoming interested in "stacking" XRP. Stacking is a process that typically refers to repeatedly purchasing small amounts of crypto on a regular basis to slowly and gradually accumulate it. It is akin to saving coins in a piggybank, except that the value of those coins may fluctuate (of course we hope that their value increases).

I began personally using a script to automatically swap my mined XMR for XRP a couple months ago and since then have had many people ask me for it, so I've decided to release it publicly. You should use a separate XMR wallet for mining. Most mining pools have a default minimum pay out amount of 0.3 or 0.03 XMR, but on some pools such as MoneroOcean, the pay out amount can be set as low at 0.001 XMR. By default, the script will check to make sure your XMR wallet contains at least 0.03 XMR, then will exchange 99% of the balance to XRP (1% is reserved for transfer fee). I run it once a day automatically by putting it in my crontab, but you can use any interval that you choose (more on this later). It requires that you have monero-wallet-rpc running - you can find instructions for that here. It also requires you to have an API key for the CEX swap provider StealthEX. I chose this swap provider because it allows extremely small amounts of XMR to be exchanged for XRP, making it ideal for stacking. Simply sign up for a free account and visit their settings page to find your API key. Additionally, your installation of PHP must have the cURL and bcmath extensions enabled.

INSTALL


Installation of Mine2XRP is done by downloading 2 PHP scripts and then setting 1 of them to automatically run in a crontab at the specified interval. The first file, stealthex_create_xmr_to_xrp_exchange.php, is responsible for setting up the XMR to XRP exchange using StealthEX. It requires you to set your StealthEX API key at the top of the file. Note that the main function in this file will output various information about the exchange created, and will return the XMR deposit address, which is used by the next file. Let's take a closer look at this file.


<?php
// StealthEX API Configuration
$apiKey = 'YOUR_API_KEY'; // Get from stealthEX.io account
$apiUrl = 'https://api.stealthex.io/api/v2/exchange';

// Exchange parameters
	function create_exchange($xmr_amount,$xrp_addr)
	{
		$params = [
		'from' => 'xmr',
		'to' => 'xrp',
		'amount' => "$xmr_amount", // Amount of XMR to exchange
		'address' => $xrp_addr // Destination XRP address
	];

	// Create cURL request
	$ch = curl_init();
	curl_setopt_array($ch, [
		CURLOPT_URL => $apiUrl,
		CURLOPT_RETURNTRANSFER => true,
		CURLOPT_POST => true,
		CURLOPT_HTTPHEADER => [
			'Content-Type: application/json',
			'X-API-KEY: ' . $apiKey
		],
		CURLOPT_POSTFIELDS => json_encode($params)
	]);

	// Execute and handle response
	$response = curl_exec($ch);
	$error = curl_error($ch);
	curl_close($ch);

	if ($error) {
		die("cURL Error: " . $error);
	}

	$data = json_decode($response, true);

	if (isset($data['error'])) {
		die("API Error: " . $data['error']);
	}

	// Output exchange details
	echo "Exchange created successfully!\n";
	echo "Exchange ID: " . $data['id'] . "\n";
	echo "Status: " . $data['status'] . "\n";
	echo "Send XMR to: " . $data['deposit_address'] . "\n";
	echo "Minimum amount: " . $data['deposit_min'] . " XMR\n";
	echo "XRP to receive: " . $data['received_amount'] . " XRP\n";
	echo "Valid until: " . date('Y-m-d H:i:s', $data['valid_until']) . "\n";
	
	return $data['deposit_address']; // return the XMR deposit address
}
?>

As you can see, the above is fairly self explanatory - all it does is use cURL to contact the StealthEX API endpoint for creating an exchange and set up an exchange for XMR to XRP. This will then be used to provide the XMR deposit address to our next file, check_balance_initiate_exchange.php, which first checks the balance of your XMR wallet (using monero-wallet-rpc), then if the balance is at least 0.03 XMR, it creates an XMR to XRP exchange, and sends 99% of the wallet balance to the exchange's deposit address (1% is left for the transfer fee, though in practice this fee should be significantly less than 1%). Let's take a closer look.


<?php
require_once("stealthex_create_xmr_to_xrp_exchange.php");

// Monero-Wallet-RPC configuration
$rpcUrl = "http://127.0.0.1:18083/json_rpc";
$rpcUser = "your_rpc_username";
$rpcPassword = "your_rpc_password";
$xrpAddress = "";
// Set the above variables

// Function to send JSON-RPC requests
function sendRpcRequest($url, $user, $password, $method, $params = []) {
    $request = json_encode([
        'jsonrpc' => '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();
}
?>


Note that both files will output exactly what they're doing. After successfully running the 2nd file, you will see output like the following.


Exchange created successfully!
Exchange ID: 123456789
Status: waiting
Send XMR to: 8ABCDEF...123456
Minimum amount: 0.03 XMR
XRP to receive: 12.34 XRP
Valid until: 2025-01-31 23:59:59
Transaction successful! TXID: f73359...123456 


The output here contains all the information you might need to check the status of your XMR transfer as well as the status of the exchange. The TXID can be used by websites like xmrchain.net to check if your XMR was successfully transferred to the deposit address, while the Exchange ID can be used to check the status of the actual exchange by visiting StealthEX.io and entering it in the drop down that appears when clicking "My Exchanges" from the main page.

The only thing left to do is install it in a crontab for automated execution. To edit your crontab on Linux/Unix, MacOS, or Cygwin (if you're running Windows, first install Cygwin, a shell that emulates most Linux commands), type crontab -e and add the following line.


0 0 * * * php /path/to/check_balance_initiate_exchange.php


Note that this will execute the script once per day at 00:00 (midnight). For other common examples of how to execute commands at regular intervals in a crontab, see crontab.guru. Additionally, you may want to check your crontab logs from time to time to see the output of the script. You can do this with the following command.


cat /var/log/syslog | grep cron


On Cygwin, the cron logfile will be in /var/log/cron.log or possibly in your $HOME directory.

Below are links to directly download the 2 PHP files shown above.
stealthex_create_xmr_to_xrp_exchange.php
check_balance_initiate_exchange.php

CONTACT

Email me at hi[at]mine2xrp.com or find me on X (@h45hb4ng)