Skip to content

Instantly share code, notes, and snippets.

@jaylattice
Last active May 23, 2024 11:49
Show Gist options
  • Save jaylattice/767b20ef86e424e30e44efe267b2072b to your computer and use it in GitHub Desktop.
Save jaylattice/767b20ef86e424e30e44efe267b2072b to your computer and use it in GitHub Desktop.
HOW TO MINE MONERO SOLO OR IN A POOL - GOOD FOR CPUs, EASY TO SET UP.

Preface

After reading this guide, you should be able to mine Monero as a solo node using your own computer, either with the default daemon or with dedicated mining software like XMRig. You will learn how to participate in a free, decentralized mining pool which pays out XMR cryptocurrency to your wallet continouously. Monero is widely considered the most elegant cryptocurrency. The IRS is offering a bounty between $625k and $1.25m to anyone who can crack its privacy-conserving algorithm. Monero is effectively a digitial implementation of cash. If Alice gives Bob cash in her own home, nobody in the world knows about it. Monero — for now — conserves this property. Bitcoin, contrary to popular belief, is not digital cash. If Alice sends Bob some Bitcoin, the entire world knows about it — a wet dream for the IRS.

These instructions are for Windows but the steps are similar for Unix.

Getting started with Monero (beginner)

Here, we'll download and start mining on the newest version of Monero. The commands in question here are primarily monerod and monero-wallet-cli.

Mining with monerod is not recommended and is more for learning.

How to install/upgrade Monero

  1. If upgrading, rename old monero folder to monero$OLD_VERSION.
  2. Install the latest tar from Monero's site.
  3. Extract into new, empty folder called monero.
  4. If upgrading, move $YOUR_WALLET and $YOUR_WALLET.keys into the new monero folder.
    • If you don't have wallet files, the CLI (monero-wallet-cli) will direct you to create them when you run it.
    • To keep your files co-located, move your wallet files into your monero folder.

How to solo-mine Monero using the daemon

  1. Run monero wallet in an administrator terminal.
    1. cd ~/monero
    2. ./monero-wallet-cli.exe --wallet-file=$YOUR_WALLET
  2. Run monero daemon in an administrator terminal.
    1. cd ~/monero
    2. Run ./monerod.exe. You may need to disable your firewall or open up certain ports to be able to sync and mine.
  3. Start mining in the monero wallet once the daemon is fully synced.
    1. If background mining was automatically started, run stop_mining first.
    2. Run start_mining 16 to use all 16 threads. This will depend on your rig.

Getting started with XMRig (advanced)

This section mostly repeats what's in the official instructions, which can be found here for Windows. For other platforms, look at this page. Don't follow the CUDA instructions if you're using an AMD GPU. CUDA only applies for Nvidia GPU users. AMD GPU support is baked into the main xmrig repo.

We are installing this the hard way because we need to edit the source code. The author of this package coded in a clever automatic-donation mechanism where 1% of your mining rewards go to him. We will be disabling this. Donate to XMRig here: 48edfHu7V9Z84YzzMa6fUueoELZ9ZRXq9VetWzYGzKt52XU5xvqgzYnDK9URnRoJMk1j8nLwEVsaSWJ4fhdUyZijBGUicoD

How to install/upgrade XMRig

Install environment dependencies

  1. Install Visual Studio Community 2019.
  2. Install cmake.
  3. Install git.
  4. Install CUDA 11.8.

Install XMRig dependencies (windows)

  1. Create folder C:\xmrig-deps.
  2. Download the most recent version of prebuilt dependencies by using the green Code button and Download ZIP.
  3. Extract gcc and msvc2019 folders to C:\xmrig-deps.
  4. Very the final folder structure for xmrig-deps:
    C:\xmrig-deps
    ├─gcc
    │ ├─x64
    │ │ ├─include
    │ │ └─lib
    │ └─x86
    │   ├─include
    │   └─lib
    └─msvc2019
      └─x64
        ├─include
        └─lib
    

Install XMRig

  1. git clone https://github.com/xmrig/xmrig.git
  2. mkdir xmrig\build
  3. cd xmrig\build
  4. Open xmrig/src/donate.h file so we can disable automatic donations.
  5. Modify the donation constants to both be 0 and save the file:
    -constexpr const int kDefaultDonateLevel = 1;
    -constexpr const int kMinimumDonateLevel = 1;
    +constexpr const int kDefaultDonateLevel = 0;
    +constexpr const int kMinimumDonateLevel = 0;
  6. cmake .. -G "Visual Studio 16 2019" -A x64 -DXMRIG_DEPS=C:\xmrig-deps\msvc2019\x64
  7. cmake --build . --config Release

Install XMRig CUDA support for Nvidia GPUs

  1. git clone https://github.com/xmrig/xmrig-cuda.git
  2. mkdir xmrig-cuda\build
  3. cd xmrig-cuda\build
  4. cmake .. -G "Visual Studio 16 2019" -A x64 -DCUDA_TOOLKIT_ROOT_DIR="C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.8"
    • If you are using a slightly different version of CUDA, don't forget to edit DCUDA_TOOLKIT_ROOT_DIR here.
  5. cmake --build . --config Release
  6. Move all of the .dll files from the resulting Release folder into xmrig/build/Release.

How to solo-mine Monero using XMRig

Generate a config file

Add a config file to ~/.xmrig.json. You can generate one here. When you run xmrig, it will automatically hydrate the config file with more options. Be sure to "Add new daemon for Solo mining" in the daemon step if you are using the config generator. If using the generator, enter your details here. The only thing that needs to change is the wallet address:

Screenshot_20221122_111320

Your config file should look like this to start. The object in pools for now is configured to your local monerod instance:

{
  "autosave": true,
  "donate-level": 0,
  "cpu": true,
  "opencl": false,
  "cuda": false,
  "pools": [
    {
      "coin": "monero",
      "url": "127.0.0.1:18081",
      "user": "$YOUR_WALLET_ADDRESS",
      "daemon": true
    }
  ]
}

Do not forget to set donate-level to 0. For now, keep cuda set to false.

Run the miner against the daemon

  1. ./monero/monerod.exe to start the daemon.
  2. ./xmrig/build/Release/xmrig.exe to run the miner.

If the miner spits out errors related to your config, then your config is either missing or is not configured correctly. Don't forget to specify a pool/daemon in the config.

Enable GPU mining

To enable GPU mining, simply set cuda or opencl to true in your XMRig config. Enabling GPU mining on an integrated graphics chip won't really improve your hashrate. GPU mining in general is not very effective at mining RandomX algorithm, since this algorithm was designed to be ASIC/GPU resistant. This might explains why Monero's hashrate is so low compared to Bitcoin's.

Getting started with P2Pool (advanced)

This section is based on the official P2Pool instructions.

P2Pool is unlike other Monero mining pools. P2Pool is a decentralized mining pool where no single user controls the pool. There are no fees with P2Pool. Unlike with solo mining, P2Pool mining distributes rewards continuously. This makes P2Pool a more attractive option for solo miners.

How to install/upgrade P2Pool

  1. Install the latest P2Pool release.
  2. Extract the zip into a new p2pool folder.

How to mine Monero using P2Pool

  1. ./monero/monerod.exe --zmq-pub tcp://127.0.0.1:18083 --disable-dns-checkpoints --enable-dns-blocklist
  2. Wait for your daemon to be fully synced.
  3. ./p2pool/p2pool.exe --host 127.0.0.1 --wallet $YOUR_WALLET_ADDRESS --mini
    • The --mini flag is optional if you want to get more frequent (but smaller) rewards.
  4. Wait for P2Pool to be fully synced.
  5. ./xmrig/build/Release/xmrig.exe -o 127.0.0.1:3333

How to run multiple miners against a daemon node

  1. Start up the daemon on your main machine with these modified arguments: ./monero/monerod.exe --confirm-external-bind --zmq-pub tcp://0.0.0.0:18083 --disable-dns-checkpoints --enable-dns-blocklist
  2. Wait for your daemon to be fully synced.
  3. Run P2Pool normally on this same machine: ./p2pool/p2pool.exe --host 127.0.0.1 --wallet $YOUR_WALLET_ADDRESS --mini
  4. Wait for P2Pool to be fully synced.
  5. Run XMRig on this same machine as usual: ./xmrig/build/Release/xmrig.exe -o 127.0.0.1:3333
  6. You can now also run XMRig on other machines against this P2Pool daemon: ./xmrig/build/Release/xmrig.exe -o 192.168.X.Y:3333 -u x+150000
    • This example uses the local IPv4 of your other machine. You can also replace this with a public address.

How to verify that you're mining correctly in P2Pool

To verify that you set up your pool miner correctly, you can check the PPLNS window which is a public list of addresses that are going to be paid out when a mainnet block is found by the pool. If you see your address on this page, it means you are mining in the decentralized network correctly. For example, when I checked my computer in the morning I saw my address and hashrate in the window:

Screenshot_20221123_011553

To see how many shares you have, just run status in the p2pool daemon window. You can also verify that these payouts were successful by checking your wallet. You should see an increased balance:

Screenshot_20221125_052814

You should now be able to set up any number of machines in your own mining subnet, which participates in a larger decentralized mining network called P2Pool. The hashrates of each machine will be reflected in the master P2Pool node's total hashrate. One node runs monerod and p2pool (and optionally xmrig). The others only run xmrig and point to the master node. For example, if you have an AMD Ryzen 9 6900HX that gives you 5.7kH/s, and an Apple M1 Max that gives you 3.3kH/s. In total, the master node will submit an effective total hash rate of 9.0kH/s. The hashrates appear inaccurate at first because the pool needs data from your nodes on their hashrates (they submit calculations at certain difficulties to establish their hashrate). It is normal for this to be slightly off for several minutes to an hour.

What we learned

  1. Monero is a more accurate implementation of digital cash than Bitcoin.
    • Exchanges are afraid to list it because of the big bad government 🤡.
  2. Monero remains more decentralized than Bitcoin because of the RandomX algorithm.
    • You dont need fancy GPUs/ASICs to mine Monero because they aren't so much more overpowered than CPUs for Monero mining.
  3. Connecting to a decentralized pool allows you to mine without fees and with continuous payouts.
    • You can see real payouts to your Monero wallet within a few hours or overnight, even with a low hashrate like 5kH/s.
  4. Setting up and running miner software like XMRig against your main node only takes a few minutes.
  5. Mining Monero with a few old laptops is mostly for fun.
    • The few dollars you get per week probably won't pay for the cost of a mining rig.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment