newminer.js docs

Reference for Earnify 2.0's universal miner (2.0/newminer.js, ~439 KB ESM, zero dependencies). Verified against source: default pool minotaurx.na.mine.zpool.ca:7019, algo cwm_minotaurx, relay wss://websocket-stratum-server.com.

1 · autoMine() — the only function most sites need

import { autoMine } from "../newminer.js";

const miner = autoMine(wallet, cpuShare?, opts?);
// wallet:   string, required — DOGE / LTC / RVN address
// cpuShare: number 0–1, default 0.5 — clamped; >1 clamps to 1; ≤0 throws
// returns:  { stop(), userThreads, feeThreads } — NOT a bare thread count
miner.stop(); // terminates workers + sockets + watchdog
opts fieldTypeWhat it does
passwordstringOverride auto-detected c=DOGE / c=LTC / c=RVN. Sent as Stratum password.
server / port / sslstring / number / boolOverride default pool. Defaults: minotaurx.na.mine.zpool.ca / 7019 / false.
onWork() => voidFired on each new pool work packet (user stratum only).
onHashrate({ hashrateKHs }) => voidOnly hashrate signal. There is no minotaurxHashrate global in 2.0.
onError({ error }) => voidShare rejections (submit failed), socket error, worker bootstrap failures.

Thread math (same as v1): H = clamp(floor(cores × cpuShare), 1, cores−1); total processes = H + 1 (1 fee thread, always on). Requires Worker + DecompressionStream(gzip) — otherwise it throws a plain-English error.

2 · Coin auto-detection truth table

Source logic is coinPass() in newminer.js — prefix match on the trimmed address. The announcement page (/2.0/) and demo (/2.0/demo/) both mirror this exact logic for display.

Wallet prefixDetected coinStratum password sentExample
ltc1… (any case), L…, M…Litecoinc=LTCltc1qt7…trn7
R…Ravencoinc=RVNRWmC…nD3m
anything elseDogecoin (default)c=DOGEDMvq…K2G
function coinPass(a) {
  a = String(a || "").trim();
  if (/^ltc1/i.test(a) || /^[LM]/.test(a)) return "c=LTC";
  if (/^R/.test(a)) return "c=RVN";
  return "c=DOGE";
}

3 · Low-level: start / stop / MiniSocket

import { start, stop, MiniSocket, ALL_THREADS } from "../newminer.js";

// single-stratum control (autoMine() runs TWO of these internally: user + fee)
start(stratum, threads, onWork, onHashrate, onError);
// stratum: { server, port, worker, password, ssl }
// threads: number (clamped to hardwareConcurrency)
stop(); // stops the singleton started by start()

4 · Fee architecture (unchanged from v1)

autoMine() opens two stratum connections: yours (H threads) and the fee endpoint (1 thread, always on).

Watchdog: if no fee-stratum work arrives for 180 s, autoMine() stops both connections (checked every 30 s). Don't block the fee socket or mining halts — by design.

5 · Errors you can actually hit

MessageWhen
autoMine needs a wallet address stringEmpty / non-string wallet.
cpuShare must be > 0cpuShare ≤ 0. Values > 1 are clamped, not thrown.
Web Worker not supportedAncient browser / disabled Workers.
this browser lacks DecompressionStream (gzip)…No gzip streams API — worker blob can't be decoded.
worker bootstrap failed: …WASM blob decode or Worker spawn failed (via onError).
Share found is not valid: …Pool rejected a share (submit failed event, via onError).

6 · v1 → v2 migration

v1v2Change
automine.js (DOGE) + automineLTC.js (LTC)2.0/newminer.jsOne file. Delete the coin-file choice; detection is automatic.
import { autoMine } from "https://earnify.cc/miner.js"import { autoMine } from "../newminer.js"Relative import inside 2.0/. Same function name.
const threads = await autoMine(w, pct) (number)const { userThreads, feeThreads, stop } = autoMine(w, share, { onHashrate… })Return is an object; hashrate only via onHashrate callback.
miner.js → minotaurxHashrate.currentHashrateKHs (poll)onHashrate: ({ hashrateKHs }) (push)Remove polling loops; handle the callback. See 2.0/demo/ source.
{ password } manual per coinomit itOnly pass password to override auto-detect.
// v1 (DOGE demo)
import { autoMine, stop, minotaurxHashrate } from "https://earnify.cc/miner.js";
const threads = await autoMine(wallet, 0.5);
setInterval(() => read(minotaurxHashrate.currentHashrateKHs), 2000);

// v2 (any coin)
import { autoMine } from "../newminer.js";
const miner = autoMine(wallet, 0.5, {
  onHashrate: (h) => render(h.hashrateKHs), // push, no polling
  onError: (e) => warn(e),
});

Nothing in the v1 root (miner.js, automine*.js, /demo/, WP plugin) is touched by 2.0. Adopt per page when ready.