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" \
In your application:
let mut miner = mining_state!;
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 ;
let mut miner = builder
.wallet
.sources
.cpu_fraction
.application_name
.consent_check
.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
[]
= ["mining"]
= ["opt-in-miner"]
[]
= { = "0.2", = true }
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 permissionset_persistence(Persistence::Save / Ask)— remember the decision or ask again each launchset_cpu_fraction(0.5)— change CPU usage immediatelyset_threads(4)— change thread count (restarts mining)toggle()— start/stop mining, or signal that consent is neededstop()/start()— pause and resume mining
Ethical guidelines for application developers
If you use this library, you are responsible for being transparent:
- Ask for consent at first launch. Use the
consent_checkcallback to show a clear, honest dialog. Do not bury it in terms of service. This is the most important step. - Make it easy to opt out. Expose the consent setting in your application's preferences. Let users change their mind.
- Keep CPU usage reasonable. The default 25% is a good starting point. Don't set it higher without reason.
- Offer alternatives. A paid version without mining, or a self-build option, gives users real choice.
- 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
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT License (LICENSE-MIT)
at your option.