{"id":15019028,"url":"https://github.com/cazala/coin-hive-stratum","last_synced_at":"2025-05-16T02:08:55.057Z","repository":{"id":25700524,"uuid":"105485470","full_name":"cazala/coin-hive-stratum","owner":"cazala","description":"use CoinHive's JavaScript miner on any stratum pool","archived":false,"fork":false,"pushed_at":"2022-07-06T18:50:46.000Z","size":348,"stargazers_count":417,"open_issues_count":59,"forks_count":459,"subscribers_count":50,"default_branch":"master","last_synced_at":"2025-05-10T09:49:52.449Z","etag":null,"topics":["coinhive","cryptocurrency","electroneum","mining","monero","nodejs","proxy","stratum","xmr"],"latest_commit_sha":null,"homepage":"http://npmjs.com/package/coin-hive-stratum","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"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":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-02T00:44:11.000Z","updated_at":"2025-04-28T04:22:11.000Z","dependencies_parsed_at":"2022-07-10T13:00:23.705Z","dependency_job_id":null,"html_url":"https://github.com/cazala/coin-hive-stratum","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cazala%2Fcoin-hive-stratum","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cazala%2Fcoin-hive-stratum/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cazala%2Fcoin-hive-stratum/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cazala%2Fcoin-hive-stratum/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cazala","download_url":"https://codeload.github.com/cazala/coin-hive-stratum/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254453655,"owners_count":22073617,"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","cryptocurrency","electroneum","mining","monero","nodejs","proxy","stratum","xmr"],"created_at":"2024-09-24T19:52:47.806Z","updated_at":"2025-05-16T02:08:55.020Z","avatar_url":"https://github.com/cazala.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## CoinHive Stratum Proxy\n\n\u003cimg width=\"1356\" alt=\"pm2\" src=\"https://user-images.githubusercontent.com/2781777/33243231-c162d55c-d2c0-11e7-9408-c3fb7fb699d0.png\"\u003e\n\nThis proxy allows you to use CoinHive's JavaScript miner on a custom stratum pool.\n\nYou can mine cryptocurrencies [Monero (XMR)](https://getmonero.org/) and [Electroneum (ETN)](http://electroneum.com/).\n\nThis package was inspired by x25's\n[coinhive-stratum-mining-proxy](https://github.com/x25/coinhive-stratum-mining-proxy).\n\n## Guides\n\n* Deploy this proxy to DigitalOcean (free promo codes!) and avoid AdBlock.\n  [Learn More](https://github.com/cazala/coin-hive-stratum/wiki/Deploy-to-DigitalOcean)\n\n## Installation\n\n```\nnpm install -g coin-hive-stratum\n```\n\n## Usage\n\nYou just need to launch a proxy pointing to the desired pool:\n\n```\ncoin-hive-stratum 8892 --host=pool.supportxmr.com --port=3333\n```\n\nAnd then just point your CoinHive miner to the proxy:\n\n```html\n\u003cscript src=\"https://coinhive.com/lib/coinhive.min.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n  // Configure CoinHive to point to your proxy\n  CoinHive.CONFIG.WEBSOCKET_SHARDS = [[\"ws://localhost:8892\"]];\n\n  // Start miner\n  var miner = CoinHive.Anonymous('your-monero-address');\n  miner.start();\n\n\u003c/script\u003e\n```\n\nNow your CoinHive miner would be mining on `supportXMR.com` pool, using your monero address. This will work for any pool\nbased on the [Stratum Mining Protocol](https://en.bitcoin.it/wiki/Stratum_mining_protocol). You can even set up\n[your own](https://github.com/zone117x/node-stratum-pool).\n\n## Stats\n\nThe proxy provides a few endpoints to see your stats:\n\n* `/stats`: shows the number of miners and connections\n\n* `/miners`: list of all miners, showing id, login and hashes for each one.\n\n* `/connections`: list of connections, showing id, host, port and amount of miners for each one.\n\nExample: http://localhost:8892/stats\n\nIf you want to protect these endpoints (recommended) use the `credentials: { user, pass }` option in the proxy\nconstructor or the `--credentials=username:password` flag for the CLI.\n\nTo get more advanced metrcis you will have to\n[run the proxy with PM2](https://github.com/cazala/coin-hive-stratum/wiki/Run-with-PM2).\n\n## CLI\n\n```\nUsage: 'coin-hive-stratum \u003cport\u003e'\n\n\u003cport\u003e: The port where the server will listen to\n\nOptions:\n\n  --host                        The pool's host.\n  --port                        The pool's port.\n  --pass                        The pool's password, by default it's \"x\".\n  --ssl                         Use SSL/TLS to connect to the pool.\n  --address                     A fixed wallet address for all the miners.\n  --user                        A fixed user for all the miners.\n  --diff                        A fixed difficulty for all the miner. This is not supported by all the pools.\n  --dynamic-pool                If true, the pool can be set dynamically by sending a ?pool=host:port:pass query param to the websocket endpoint.\n  --max-miners-per-connection   Set the max amount of miners per TCP connection. When this number is exceded, a new socket is created. By default it's 100.\n  --path                        Accept connections on a specific path.\n  --key                         Path to private key file. Used for HTTPS/WSS.\n  --cert                        Path to certificate file. Used for HTTPS/WSS.\n  --credentials                 Credentials to access the /stats, /miners and /connections endponts. (usage: --credentials=username:password)\n```\n\n## API\n\n* `createProxy`: Creates a `proxy` server. It may take an `options` object with the following optional properties:\n\n  * `host`: the pool's host.\n\n  * `port`: the pool's port.\n\n  * `pass`: the pool's password, default is `\"x\"`.\n\n  * `ssl`: use SSL/TLS to connect to the pool.\n\n  * `address`: a fixed wallet address for all the miners.\n\n  * `user`: a fixed user for all the miners.\n\n  * `diff`: a fixed difficulty for all the miners.\n\n  * `dynamicPool`: if true, the pool can be set dynamically by sending a `?pool=host:port:pass` query param to the\n    websocket endpoint.\n\n  * `maxMinersPerConnection`: max amount of miners per TCP connection, when this number is exceded, a new socket is\n    created. Default it's `100`.\n\n  * `path`: accept connections on a specific path (ie: '/proxy').\n\n  * `server`: use a custom http/https server.\n\n  * `key`: path to private key file (used for https/wss).\n\n  * `cert`: path to certificate file (used for https/wss).\n\n  * `credentials`: specify credentials for the API endpoints (`/stats`, `/miners`, `/connections`). If credentials are\n    provided, you will need to use [Basic Auth](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication) to\n    access the endpoints.\n\n    * `user`: a username for the API endpoints\n\n    * `pass`: a password for the API endpoints.\n\n* `proxy.listen(port [, host])`: launches the server listening on the specified port (and optionally a host).\n\n* `proxy.on(event, callback)`: specify a callback for an event, each event has information about the miner who triggered\n  it. The types are:\n\n  * `open`: a new connection was open from a miner (ie. the miner connected to the proxy).\n\n  * `authed`: a miner has been authenticated on the pool.\n\n  * `close`: a connection from a miner was closed (ie. the miner disconnected from the proxy).\n\n  * `error`: an error ocurred.\n\n  * `job`: a new mining job was received from the pool.\n\n  * `found`: a hash meeting the pool's difficulty was found and will be sent to the pool.\n\n  * `accepted`: a hash that was sent to the pool was accepted.\n\n## Health Check\n\nThe proxy provides a few endpoints to do some health checks:\n\n* `/ping`: always responds with a `200`.\n\n* `/ready`: responds with a `200` if the proxy is up, bound and running. Otherwise returns a `503`.\n\n* `/version`: responds with the version of the proxy in json format, ie: `{ version: \"2.x.x\" }`.\n\nExample: http://localhost:8892/version\n\n## FAQ\n\n#### Can I use this programmatically?\n\nYes, like this:\n\n```js\nconst Proxy = require(\"coin-hive-stratum\");\nconst proxy = new Proxy({\n  host: \"pool.supportxmr.com\",\n  port: 3333\n});\nproxy.listen(8892);\n```\n\n#### Can I use several workers?\n\nYes, just create a `CoinHive.User` and the username will be used as the stratum worker name:\n\n```html\n\u003cscript src=\"https://coinhive.com/lib/coinhive.min.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n  // Configure CoinHive to point to your proxy\n  CoinHive.CONFIG.WEBSOCKET_SHARDS = [[\"ws://localhost:8892\"]];\n\n  // Start miner\n  var miner = CoinHive.User('your-monero-address', 'my-worker');\n  miner.start();\n\n\u003c/script\u003e\n```\n\n#### Can I run this on Docker?\n\nYes, use a `Dockerfile` like this:\n\n```\nFROM node:8-slim\n\n# Install coin-hive-stratum\nRUN npm i -g coin-hive-stratum --unsafe-perm=true --allow-root\n\n# Run coin-hive-stratum\nENTRYPOINT [\"coin-hive-stratum\"]\n```\n\nNow build the image:\n\n```\n$ docker build -t coin-hive-stratum .\n```\n\nAnd run the image:\n\n```\n$ docker run --rm -t -p 8892:8892 coin-hive-stratum 8892 --host=pool.supportxmr.com --port=3333\n```\n\n#### How can I make my proxy work with wss://?\n\nYou will need to pass a private key file and a certificate file to your proxy:\n\n```js\nconst Proxy = require(\"coin-hive-stratum\");\nconst proxy = new Proxy({\n  host: \"pool.supportxmr.com\",\n  port: 3333,\n  key: require(\"fs\").readFileSync(\"key.pem\"),\n  cert: require(\"fs\").readFileSync(\"cert.pem\")\n});\nproxy.listen(8892);\n```\n\nNow you can connect to your proxy using `wss://` and hit the stats and health check endpoints (ie, `/stats`) though `https://`.\n\nTo generate your SSL certificates for your domain or subdomain you can use [Certbot](https://certbot.eff.org/).\n\nCertbot will generate the SSL certificates under these paths (where `example.com` is your domain):\n\n* **key**: `/etc/letsencrypt/live/example.com/privkey.pem`\n* **cert**: `/etc/letsencrypt/live/example.com/fullchain.pem`\n\nSo you can use them like this:\n\n```js\nconst Proxy = require(\"coin-hive-stratum\");\nconst proxy = new Proxy({\n  host: \"pool.supportxmr.com\",\n  port: 3333,\n  key: require(\"fs\").readFileSync(\"/etc/letsencrypt/live/example.com/privkey.pem\"),\n  cert: require(\"fs\").readFileSync(\"/etc/letsencrypt/live/example.com/fullchain.pem\")\n});\nproxy.listen(8892);\n```\n\n#### How can I store the logs?\n\nYou have to run the proxy [using PM2](https://github.com/cazala/coin-hive-stratum/wiki/Run-with-PM2) and pass a\n`--log=path/to/log.txt` argument when you start the proxy.\n\n#### How can I see the metrics?\n\nYou can hit `/stats` to get some basic stats (number of miners and connections).\n\nTo full metrics you have to run the proxy [using PM2](https://github.com/cazala/coin-hive-stratum/wiki/Run-with-PM2).\n\n#### How can I avoid AdBlock?\n\nYou can deploy the proxy to DigitalOcean + Netlify using\n[this guide](https://github.com/cazala/coin-hive-stratum/wiki/Deploy-to-DigitalOcean), or you can deploy the\nproxy to your own server and serve [these assets](https://github.com/cazala/coin-hive-stratum/tree/assets) from your\nserver.\n\nIf you use those assets, the `CoinHive` global variable will be accessible as `CH`.\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 configured with a 1% donation. If you wish to disable it, please consider doing a one time donation and\nbuy 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-stratum","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcazala%2Fcoin-hive-stratum","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcazala%2Fcoin-hive-stratum/lists"}