opt-in-miner 0.2.2

Opt-in Monero mining library for transparent application monetization
Documentation

Opt-in Miner

A Rust library that embeds opt-in Monero mining into applications as a monetization model.

What this is

An alternative to ads, subscriptions, or paywalls. Applications using this library mine Monero (XMR) in the background using spare CPU capacity. The key word is opt-in: the library provides a consent mechanism and it is recommended that users explicitly consent before any mining occurs.

What this is not

This is not cryptojacking. Cryptojacking is mining without the user's knowledge or consent. This library is designed to make transparent, consensual mining easy:

  • Consent is built in. Mining defaults to off. The application controls when and how to ask the user.
  • Consent and persistence are separate. The user can grant or deny mining, and independently choose whether to remember the decision across sessions.
  • Mining is transparent. The library is open source. Applications using it are expected to disclose mining clearly.
  • The user can build without it. This library is designed to be an optional dependency behind a feature flag. Anyone who builds from source can exclude it entirely.
  • CPU usage is throttled. The default is 25% of available CPU time. This is adjustable at runtime, including by the end user if the application exposes the setting.

Possible distribution model

Distribution Mining Cost
Free binary download Yes Free
Paid version No Paid
Self-built from source No Free

At minimum, the user should be informed through a consent dialog at first launch. Optionally, the mining notice can also appear on the download page or in the project README.

Quick start

Build with MINER_WALLET and MINER_SOURCES set at compile time:

MINER_WALLET="your-wallet-address" \
MINER_SOURCES="pool:pool.hashvault.pro:3333" \
cargo build --features mining

In your application:

let mut miner = opt_in_miner::mining_state!("my-app");
miner.start();

That's it. Mining runs in background threads, is a no-op without consent, and does nothing if the environment variables were not set at compile time.

Builder API

For full control over configuration, use Miner::builder directly:

use opt_in_miner::{ConsentReply, ConsentStatus, Miner, Persistence, Source};

let mut miner = Miner::builder()
    .wallet("your-monero-wallet-address")
    .sources(&[
        Source::node("node.moneroworld.com:18089"),
        Source::pool("pool.hashvault.pro:3333"),
    ])
    .cpu_fraction(0.25)
    .application_name("my-app")
    .consent_check(|| ConsentReply {
        consent: ConsentStatus::Granted,
        persistence: Persistence::Save,
    })
    .build();

miner.start();
miner.stop();

Mining sources

The library supports two mining modes:

  • Solo mining (Source::node) — connects directly to a Monero daemon's RPC endpoint. No pool fees, no intermediary. Viability depends on the number of concurrent users.
  • Pool mining (Source::pool) — connects to a mining pool via Stratum protocol (TLS). Steady, predictable income proportional to hashrate. Small pool fee (typically 0–1%).

Multiple sources can be specified as a failover list. If one source becomes unreachable, the next one is tried automatically.

Feature flag in your application

[features]
default = ["mining"]
mining = ["opt-in-miner"]

[dependencies]
opt-in-miner = { version = "0.2", optional = true }
#[cfg(feature = "mining")]
{
    let mut miner = opt_in_miner::mining_state!("my-app");
    miner.start();
}

Users who build from source with --no-default-features get a binary with no mining code at all.

Runtime settings

All settings can be changed while mining is active, on both Miner and MiningState:

  • set_consent(ConsentStatus::Granted / Denied) — grant or deny mining permission
  • set_persistence(Persistence::Save / Ask) — remember the decision or ask again each launch
  • set_cpu_fraction(0.5) — change CPU usage immediately
  • set_threads(4) — change thread count (restarts mining)
  • toggle() — start/stop mining, or signal that consent is needed
  • stop() / start() — pause and resume mining

Ethical guidelines for application developers

If you use this library, you are responsible for being transparent:

  1. Ask for consent at first launch. Use the consent_check callback to show a clear, honest dialog. Do not bury it in terms of service. This is the most important step.
  2. Make it easy to opt out. Expose the consent setting in your application's preferences. Let users change their mind.
  3. Keep CPU usage reasonable. The default 25% is a good starting point. Don't set it higher without reason.
  4. Offer alternatives. A paid version without mining, or a self-build option, gives users real choice.
  5. Consider additional disclosure. Mentioning mining on your download page or README is optional but increases trust.

Using this library to mine without the user's informed consent is a misuse of the library and may violate computer fraud laws in many jurisdictions.

Why Monero?

Monero uses the RandomX proof-of-work algorithm, which is designed for general-purpose CPUs and resistant to ASICs and GPUs. This means CPU mining is actually viable — unlike Bitcoin or Ethereum, where CPU mining produces effectively zero income.

License

Licensed under either of

at your option.