Home

Awesome

CoinHive Build Status

Mine cryptocurrencies Monero (XMR) and Electroneum (ETN) using CoinHive from node.js

New: Now you can run this miner on any stratum based pool.

New 2: Now you can mine Electroneum (ETN).

Need a proxy? check coin-hive-stratum.

Install

npm install -g coin-hive

Usage

const CoinHive = require('coin-hive');

(async () => {
  // Create miner
  const miner = await CoinHive('ZM4gjqQ0jh0jbZ3tZDByOXAjyotDbo00'); // CoinHive's Site Key

  // Start miner
  await miner.start();

  // Listen on events
  miner.on('found', () => console.log('Found!'));
  miner.on('accepted', () => console.log('Accepted!'));
  miner.on('update', data =>
    console.log(`
    Hashes per second: ${data.hashesPerSecond}
    Total hashes: ${data.totalHashes}
    Accepted hashes: ${data.acceptedHashes}
  `)
  );

  // Stop miner
  setTimeout(async () => await miner.stop(), 60000);
})();

CLI

Usage:

coin-hive ZM4gjqQ0jh0jbZ3tZDByOXAjyotDbo00

Options:

  --username        Set a username for the miner
  --interval        Interval between updates (logs)
  --port            Port for the miner server
  --host            Host for the miner server
  --threads         Number of threads for the miner
  --throttle        The fraction of time that threads should be idle
  --proxy           Proxy socket 5/4, for example: socks5://127.0.0.1:9050
  --puppeteer-url   URL where puppeteer will point to, by default is miner server (host:port)
  --miner-url       URL of CoinHive's JavaScript miner, can be set to use a proxy
  --dev-fee         A donation to the developer, the default is 0.001 (0.1%)
  --pool-host       A custom stratum pool host, it must be used in combination with --pool-port
  --pool-port       A custom stratum pool port, it must be used in combination with --pool-host
  --pool-pass       A custom stratum pool password, if not provided the default one is 'x'

API

var miner = await CoinHive('SITE_KEY');
await miner.rpc('isRunning'); // false
await miner.start();
await miner.rpc('isRunning'); // true
await miner.rpc('getThrottle'); // 0
await miner.rpc('setThrottle', [0.5]);
await miner.rpc('getThrottle'); // 0.5

Environment Variables

All the following environment variables can be used to configure the miner from the outside:

FAQ

Can I run this on a different pool than CoinHive's?

Yes, you can run this on any pool based on the Stratum Mining Protocol.

const CoinHive = require('coin-hive');
(async () => {
  const miner = await CoinHive('<YOUR-MONERO-ADDRESS>', {
    pool: {
      host: 'la01.supportxmr.com',
      port: 3333,
      pass: '<YOUR-PASSWORD-FOR-POOL>' // default 'x' if not provided
    }
  });
  await miner.start();
  miner.on('found', () => console.log('Found!'));
  miner.on('accepted', () => console.log('Accepted!'));
  miner.on('update', data =>
    console.log(`
    Hashes per second: ${data.hashesPerSecond}
    Total hashes: ${data.totalHashes}
    Accepted hashes: ${data.acceptedHashes}
  `)
  );
})();

Now your CoinHive miner would be mining on supportXMR.com pool, using your monero address.

You can also do this using the CLI:

coin-hive <YOUR-MONERO-ADDRESS> --pool-host=la01.supportxmr.com --pool-port=3333 --pool-pass=<YOUR-PASSWORD-FOR-POOL>

Can I mine other cryptocurrency than Monero (XMR)?

Yes, you can also mine Electroneum (ETN), you can actually mine on any pool based on the Stratum Mining Protocol and any coin based on CryptoNight.

You can go get you ETN wallet from electroneum.com if you don't have one.

const CoinHive = require('coin-hive');
const miner = await CoinHive('<YOUR-ELECTRONEUM-ADDRESS>', {
  pool: {
    host: 'etn-pool.proxpool.com',
    port: 3333
  }
});
miner.start();

Now your CoinHive miner would be mining on etn.proxpool.com pool, using your electroneum address.

You can also do this using the CLI:

coin-hive <YOUR-ELECTRONEUM-ADDRESS> --pool-host=etn-pool.proxpool.com --pool-port=3333

One of the features of Electroneum is that it has a difficulty of 100, while CoinHive's is 256.

Can I run this on Heroku?

No, it violates the TOS.

Also, since Puppeteer requires some additional dependencies that aren't included on the Linux box that Heroku spins up for you, you need to go to your app's Settings > Buildpacks first and add this url:

https://github.com/jontewks/puppeteer-heroku-buildpack

On the next deploy, your app will also install the dependencies that Puppeteer needs to run.

Can I run this on Docker?

You'll need to install the latest version of Chrome and Puppeteer's dependencies in your Dockerfile:

FROM node:8-slim

# Install latest chrome and puppeteer dependencies
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - &&\
sh -c 'echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list' &&\
apt-get update &&\
apt-get install -y google-chrome-unstable gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget

# Install coin-hive
RUN npm i -g coin-hive --unsafe-perm=true --allow-root

# Run coin-hive
CMD coin-hive <site-key>

Which version of Node.js do I need?

Node v8+

Troubleshooting

I'm having errors on Ubuntu/Debian

Install these dependencies:

sudo apt-get -y install gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget libxext6

I'm getting an Error: EACCES: permission denied when installing the package

Try installing the package using this:

sudo npm i -g coin-hive --unsafe-perm=true --allow-root

An error occured Failed to launch chrome!

Try changing chromium's executable path to /usr/bin/chromium-browser, like this:

const miner = await CoinHive('site-key', {
  launch: {
    executablePath: '/usr/bin/chromium-browser',
    args: ['--disable-setuid-sandbox', '--no-sandbox']
  }
});

For more info check issue #54

Disclaimer

This project is not endorsed by or affiliated with coinhive.com in any way.

Support

This project is pre-configured for a 0.1% donation. This can be easily toggled off programatically, from the CLI, or via environment variables. If you do so, but you still want to show your support, you can buy me a beer with magic internet money:

BTC: 16ePagGBbHfm2d6esjMXcUBTNgqpnLWNeK
ETH: 0xa423bfe9db2dc125dd3b56f215e09658491cc556
LTC: LeeemeZj6YL6pkTTtEGHFD6idDxHBF2HXa
XMR: 46WNbmwXpYxiBpkbHjAgjC65cyzAxtaaBQjcGpAZquhBKw2r8NtPQniEgMJcwFMCZzSBrEJtmPsTR54MoGBDbjTi2W1XmgM

<3