{"id":13432125,"url":"https://github.com/cazala/coin-hive","last_synced_at":"2025-04-13T22:29:42.106Z","repository":{"id":54274226,"uuid":"103619426","full_name":"cazala/coin-hive","owner":"cazala","description":"CoinHive cryptocurrency miner for node.js","archived":false,"fork":false,"pushed_at":"2018-12-18T06:49:20.000Z","size":196,"stargazers_count":1993,"open_issues_count":31,"forks_count":396,"subscribers_count":115,"default_branch":"master","last_synced_at":"2025-04-06T19:08:35.931Z","etag":null,"topics":["coinhive","cyptocurrency","electroneum","miner","monero","nodejs","xmr"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/coin-hive","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cazala.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-09-15T05:54:41.000Z","updated_at":"2025-03-29T22:54:44.000Z","dependencies_parsed_at":"2022-08-13T10:40:37.469Z","dependency_job_id":null,"html_url":"https://github.com/cazala/coin-hive","commit_stats":null,"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cazala%2Fcoin-hive","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cazala%2Fcoin-hive/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cazala%2Fcoin-hive/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cazala%2Fcoin-hive/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cazala","download_url":"https://codeload.github.com/cazala/coin-hive/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248790481,"owners_count":21162015,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["coinhive","cyptocurrency","electroneum","miner","monero","nodejs","xmr"],"created_at":"2024-07-31T02:01:08.782Z","updated_at":"2025-04-13T22:29:42.059Z","avatar_url":"https://github.com/cazala.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","Public Chain","📦 Legacy \u0026 Inactive Projects"],"sub_categories":["Others"],"readme":"# CoinHive [![Build Status](https://travis-ci.org/cazala/coin-hive.svg?branch=master)](https://travis-ci.org/cazala/coin-hive)\n\nMine cryptocurrencies [Monero (XMR)](https://getmonero.org/) and [Electroneum (ETN)](http://electroneum.com/) using [CoinHive](https://coinhive.com/) from node.js\n\n**New:** Now you can [run this miner on any stratum based pool](https://github.com/cazala/coin-hive#faq).\n\n**New 2:** Now you can [mine Electroneum (ETN)](https://github.com/cazala/coin-hive#can-i-mine-other-cryptocurrency-than-monero-xmr).\n\n**Need a proxy?** check [coin-hive-stratum](https://github.com/cazala/coin-hive-stratum).\n\n## Install\n\n```\nnpm install -g coin-hive\n```\n\n## Usage\n\n```js\nconst CoinHive = require('coin-hive');\n\n(async () =\u003e {\n  // Create miner\n  const miner = await CoinHive('ZM4gjqQ0jh0jbZ3tZDByOXAjyotDbo00'); // CoinHive's Site Key\n\n  // Start miner\n  await miner.start();\n\n  // Listen on events\n  miner.on('found', () =\u003e console.log('Found!'));\n  miner.on('accepted', () =\u003e console.log('Accepted!'));\n  miner.on('update', data =\u003e\n    console.log(`\n    Hashes per second: ${data.hashesPerSecond}\n    Total hashes: ${data.totalHashes}\n    Accepted hashes: ${data.acceptedHashes}\n  `)\n  );\n\n  // Stop miner\n  setTimeout(async () =\u003e await miner.stop(), 60000);\n})();\n```\n\n## CLI\n\nUsage:\n\n```\ncoin-hive ZM4gjqQ0jh0jbZ3tZDByOXAjyotDbo00\n```\n\nOptions:\n\n```\n  --username        Set a username for the miner\n  --interval        Interval between updates (logs)\n  --port            Port for the miner server\n  --host            Host for the miner server\n  --threads         Number of threads for the miner\n  --throttle        The fraction of time that threads should be idle\n  --proxy           Proxy socket 5/4, for example: socks5://127.0.0.1:9050\n  --puppeteer-url   URL where puppeteer will point to, by default is miner server (host:port)\n  --miner-url       URL of CoinHive's JavaScript miner, can be set to use a proxy\n  --dev-fee         A donation to the developer, the default is 0.001 (0.1%)\n  --pool-host       A custom stratum pool host, it must be used in combination with --pool-port\n  --pool-port       A custom stratum pool port, it must be used in combination with --pool-host\n  --pool-pass       A custom stratum pool password, if not provided the default one is 'x'\n```\n\n## API\n\n* `CoinHive(siteKey[, options])`: Returns a promise of a `Miner` instance. It requires a [CoinHive Site Key](https://coinhive.com/settings/sites). The `options` object is optional and may contain the following properties:\n\n  * `username`: Set a username for the miner. See [CoinHive.User](https://coinhive.com/documentation/miner#coinhive-user).\n\n  * `interval`: Interval between `update` events in ms. Default is `1000`.\n\n  * `port`: Port for the miner server. Default is `3002`.\n\n  * `host`: Host for the miner server. Default is `localhost`.\n\n  * `threads`: Number of threads. Default is `navigator.hardwareConcurrency` (number of CPU cores).\n\n  * `throttle`: The fraction of time that threads should be idle. Default is `0`.\n\n  * `proxy`: Puppeteer's proxy socket 5/4 (ie: `socks5://127.0.0.1:9050`).\n\n  * `launch`: The options that will be passed to `puppeteer.launch(options)`. See [Puppeteer Docs](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#puppeteerlaunchoptions).\n\n  * `pool`: This allows you to use a different pool. It has to be an [Stratum](https://en.bitcoin.it/wiki/Stratum_mining_protocol) based pool. This object must contain the following properties:\n\n    * `host`: The pool's host.\n\n    * `port`: The pool's port.\n\n    * `pass`: The pool's password. If not provided the default one is `\"x\"`.\n\n  * `devFee`: A donation to send to the developer. Default is `0.001` (0.1%).\n\n* `miner.start()`: Connect to the pool and start mining. Returns a promise that will resolve once the miner is started.\n\n* `miner.stop()`: Stop mining and disconnect from the pool. Returns a promise that will resolve once the miner is stopped.\n\n* `miner.kill()`: Stop mining, disconnect from the pool, shutdown the server and close the headless browser. Returns a promise that will resolve once the miner is dead.\n\n* `miner.on(event, callback)`: Specify a callback for an event. The event types are:\n\n  * `update`: Informs `hashesPerSecond`, `totalHashes` and `acceptedHashes`.\n\n  * `open`: The connection to our mining pool was opened. Usually happens shortly after miner.start() was called.\n\n  * `authed`: The miner successfully authed with the mining pool and the siteKey was verified. Usually happens right after open.\n\n  * `close`: The connection to the pool was closed. Usually happens when miner.stop() was called.\n\n  * `error`: An error occured. In case of a connection error, the miner will automatically try to reconnect to the pool.\n\n  * `job`: A new mining job was received from the pool.\n\n  * `found`: A hash meeting the pool's difficulty (currently 256) was found and will be send to the pool.\n\n  * `accepted`: A hash that was sent to the pool was accepted.\n\n* `miner.rpc(methodName, argsArray)`: This method allows you to interact with the CoinHive miner instance. It returns a Promise that resolves the the value of the remote method that was called. The miner instance API can be [found here](https://coin-hive.com/documentation/miner#miner-is-running). Here's an example:\n\n```js\nvar miner = await CoinHive('SITE_KEY');\nawait miner.rpc('isRunning'); // false\nawait miner.start();\nawait miner.rpc('isRunning'); // true\nawait miner.rpc('getThrottle'); // 0\nawait miner.rpc('setThrottle', [0.5]);\nawait miner.rpc('getThrottle'); // 0.5\n```\n\n## Environment Variables\n\nAll the following environment variables can be used to configure the miner from the outside:\n\n* `COINHIVE_SITE_KEY`: CoinHive's Site Key\n\n* `COINHIVE_USERNAME`: Set a username to the miner. See [CoinHive.User](https://coinhive.com/documentation/miner#coinhive-user).\n\n* `COINHIVE_INTERVAL`: The interval on which the miner reports an update\n\n* `COINHIVE_THREADS`: Number of threads\n\n* `COINHIVE_THROTTLE`: The fraction of time that threads should be idle\n\n* `COINHIVE_PORT`: The port that will be used to launch the server, and where puppeteer will point to\n\n* `COINHIVE_HOST`: The host that will be used to launch the server, and where puppeteer will point to\n\n* `COINHIVE_PUPPETEER_URL`: In case you don't want to point puppeteer to the local server, you can use this to make it point somewhere else where the miner is served (ie: `COINHIVE_PUPPETEER_URL=http://coin-hive.herokuapp.com`)\n\n* `COINHIVE_MINER_URL`: Set the CoinHive JavaScript Miner url. By defualt this is `https://coinhive.com/lib/coinhive.min.js`. You can set this to use a [CoinHive Proxy](https://github.com/cazala/coin-hive-proxy).\n\n* `COINHIVE_PROXY`: Puppeteer's proxy socket 5/4 (ie: `COINHIVE_PROXY=socks5://127.0.0.1:9050`)\n\n* `COINHIVE_DEV_FEE`: A donation to the developer, the default is 0.001 (0.1%).\n\n* `COINHIVE_POOL_HOST`: A custom stratum pool host, it must be used in combination with `COINHIVE_POOL_PORT`.\n\n* `COINHIVE_POOL_PORT`: A custom stratum pool port, it must be used in combination with `COINHIVE_POOL_HOST`.\n\n* `COINHIVE_POOL_PASS`: A custom stratum pool password, if not provided the default one is 'x'.\n\n## FAQ\n\n#### Can I run this on a different pool than CoinHive's?\n\nYes, you can run this on any pool based on the [Stratum Mining Protocol](https://en.bitcoin.it/wiki/Stratum_mining_protocol).\n\n```js\nconst CoinHive = require('coin-hive');\n(async () =\u003e {\n  const miner = await CoinHive('\u003cYOUR-MONERO-ADDRESS\u003e', {\n    pool: {\n      host: 'la01.supportxmr.com',\n      port: 3333,\n      pass: '\u003cYOUR-PASSWORD-FOR-POOL\u003e' // default 'x' if not provided\n    }\n  });\n  await miner.start();\n  miner.on('found', () =\u003e console.log('Found!'));\n  miner.on('accepted', () =\u003e console.log('Accepted!'));\n  miner.on('update', data =\u003e\n    console.log(`\n    Hashes per second: ${data.hashesPerSecond}\n    Total hashes: ${data.totalHashes}\n    Accepted hashes: ${data.acceptedHashes}\n  `)\n  );\n})();\n```\n\nNow your CoinHive miner would be mining on `supportXMR.com` pool, using your monero address.\n\nYou can also do this using the CLI:\n\n```\ncoin-hive \u003cYOUR-MONERO-ADDRESS\u003e --pool-host=la01.supportxmr.com --pool-port=3333 --pool-pass=\u003cYOUR-PASSWORD-FOR-POOL\u003e\n```\n\n#### Can I mine other cryptocurrency than Monero (XMR)?\n\nYes, you can also mine [Electroneum (ETN)](https://electroneum.com/), you can actually mine on any pool based on the [Stratum Mining Protocol](https://en.bitcoin.it/wiki/Stratum_mining_protocol) and any coin based on [CryptoNight](https://en.bitcoin.it/wiki/CryptoNight).\n\nYou can go get you ETN wallet from [electroneum.com](https://downloads.electroneum.com/offline_paper_electroneum_walletV1.5.html) if you don't have one.\n\n```js\nconst CoinHive = require('coin-hive');\nconst miner = await CoinHive('\u003cYOUR-ELECTRONEUM-ADDRESS\u003e', {\n  pool: {\n    host: 'etn-pool.proxpool.com',\n    port: 3333\n  }\n});\nminer.start();\n```\n\nNow your CoinHive miner would be mining on `etn.proxpool.com` pool, using your electroneum address.\n\nYou can also do this using the CLI:\n\n```\ncoin-hive \u003cYOUR-ELECTRONEUM-ADDRESS\u003e --pool-host=etn-pool.proxpool.com --pool-port=3333\n```\n\nOne of the features of Electroneum is that it has a difficulty of `100`, while CoinHive's is `256`.\n\n#### Can I run this on Heroku?\n\nNo, it violates the [TOS](https://www.heroku.com/policy/aup).\n\nAlso, 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 \u003e Buildpacks` first and add this url:\n\n```\nhttps://github.com/jontewks/puppeteer-heroku-buildpack\n```\n\nOn the next deploy, your app will also install the dependencies that Puppeteer needs to run.\n\n#### Can I run this on Docker?\n\nYou'll need to install the latest version of Chrome and Puppeteer's dependencies in your Dockerfile:\n\n```\nFROM node:8-slim\n\n# Install latest chrome and puppeteer dependencies\nRUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \u0026\u0026\\\nsh -c 'echo \"deb http://dl.google.com/linux/chrome/deb/ stable main\" \u003e\u003e /etc/apt/sources.list.d/google-chrome.list' \u0026\u0026\\\napt-get update \u0026\u0026\\\napt-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\n\n# Install coin-hive\nRUN npm i -g coin-hive --unsafe-perm=true --allow-root\n\n# Run coin-hive\nCMD coin-hive \u003csite-key\u003e\n```\n\n#### Which version of Node.js do I need?\n\nNode v8+\n\n## Troubleshooting\n\n#### I'm having errors on Ubuntu/Debian\n\nInstall these dependencies:\n\n```\nsudo 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\n```\n\n#### I'm getting an Error: EACCES: permission denied when installing the package\n\nTry installing the package using this:\n\n```\nsudo npm i -g coin-hive --unsafe-perm=true --allow-root\n```\n\n#### An error occured Failed to launch chrome!\n\nTry changing chromium's executable path to `/usr/bin/chromium-browser`, like this:\n\n```js\nconst miner = await CoinHive('site-key', {\n  launch: {\n    executablePath: '/usr/bin/chromium-browser',\n    args: ['--disable-setuid-sandbox', '--no-sandbox']\n  }\n});\n```\n\nFor more info check issue [#54](https://github.com/cazala/coin-hive/issues/54)\n\n## Disclaimer\n\nThis project is not endorsed by or affiliated with `coinhive.com` in any way.\n\n## Support\n\nThis 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](https://i.imgur.com/mScSiOo.jpg):\n\n```\nBTC: 16ePagGBbHfm2d6esjMXcUBTNgqpnLWNeK\nETH: 0xa423bfe9db2dc125dd3b56f215e09658491cc556\nLTC: LeeemeZj6YL6pkTTtEGHFD6idDxHBF2HXa\nXMR: 46WNbmwXpYxiBpkbHjAgjC65cyzAxtaaBQjcGpAZquhBKw2r8NtPQniEgMJcwFMCZzSBrEJtmPsTR54MoGBDbjTi2W1XmgM\n```\n\n\u003c3\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcazala%2Fcoin-hive","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcazala%2Fcoin-hive","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcazala%2Fcoin-hive/lists"}