Adding a Monero miner to your website

If you love cryptocurrency, hate pesky internet ads and manage a website or webpage, then this is the guide for you.

Let me start off by saying that throughout this guide I am in no way endorsing cryptocurrency.
This guide is written purely to show that there are more options to make 'money' from your website other than displaying only visual advertisements. I will not be held responsable for any misuse of the cryptocurrency miner shown in this guide.

What is Monero and what is mining?

Instead of me trying to give a half-pie definition of what Monero is, im going to include the definition from the website

"Monero (XMR) is a cryptocurrency focuses on being untraceable and private. Its design differs
from Bitcoin’s in a few key ways, but it should be understood as a cryptocurrency similar to Bitcoin – it
can be used to buy and sell things, and can be exchanged for other coins or tokens."

If your still eager to find more information on Monero you can visit the official website.

So now that you have an understanding of what Monero is you need to know what the term 'mining' means. To explain mining in its most basic form, cryptocurrency mining is a way of earning cryptocurrency through your computer solving complex mathematical equations. The mathematical equations are normally processed by your computers central processing unit (CPU) or graphical processing unit (GPU).

Mining is usually controlled through a computer program, but we will be using a web browser to get website visitors to mine Monero for us.

Why should I get rid of website ads?

Well i'm not saying that you should, but let me point out some facts.

- When monetizing with ads, the ad platform that distributes the ads pays out in your country's currency.
- Monero is a cryptocurrency, you would need to find a buyer in order to exchange for your local currency, find retailers that accept monero or hodl.

Make sure you keep in mind the whole cash vs crypto payouts if you are thinking about making the switch from ads. I strongly discourage from having both ads and mining crypto on the same page of your site. Personally if I was to display ads or mine crypto on this website, I would lean toward mining crypto, only reason being to maintain a clean-looking website.

You won't see any ads on this website nor will I run any cryptocurrency miners ( I promise :-).

Adding the miner to your website

The adding of the miner to your website is a very simple task. The miner service Coinhive that we will be using for this guide offers many miner customisation options with their API. For the sake of this guide we will stick to Coinhive's recommended mining script.

Copy and paste the below script between your body tags on your web page. Replace the left and right parenthesis () from around the word script with < & >. I had to replace brackets with left and right parenthesis as this webpage would attempt to load the miner script.

   (script src="">(/script)
   var miner = new CoinHive.Anonymous('YOUR_SITE_KEY', {throttle: 0.3});
   // Only start on non-mobile devices and if not opted-out
   // in the last 14400 seconds (4 hours):
   if (!miner.isMobile() && !miner.didOptOut(14400)) {

The above script sets the user's CPU usage to mine at 70%. The script will also disable the miner if the user is viewing the page on a mobile device (in most cases the users mobile device will slow).

Attaching your site key to the miner script

Now you have added the miner to your web page you will need to link it to something called a site key. Don't show people your private site key, I have revoked the above key so it can't be used.

Coinhive Public Site Key

Open the 'Coinhive homepage and click on sign up in the top right corner. Enter your details and continue, verify your email address, come back to the website and click into settings. When in setting open 'Sites & API Keys', in the name text box type your website URL e.g., and click save site name. Now copy the 'Site Key (public)' it will a bunch of combined letters and numbers. Open up the miner script from earlier and paste your public site key to where it says YOUR_SITE_KEY.

The site key directs all mined monero from your website to your Coinhive account. A summary of the Monero that's mined from your website can be found on the 'Coinhive Mining Tool' section on the Coinhive website.

You will now need to provide your Monero wallet address to Coinhive, when you reach the threshold Coinhive will pay out to your wallet address. To input wallet address go to the payments section in the settings menu.

Dont have a Monero wallet? Watch this guide to set one up.

This guide has only scraped the surface of explaining what the Coinhive miner can do especially with offered the API. If you want to learn more about what you can do with the miner, make sure to read the extensive documentation on the Coinhive website.

Richard Motion Portrait Image

Richard Motion

I am a New Zealand based tech enthusiast with a passion for learning all things tech related. My hobbies include playing video games and watching movies. If you like what i'm doing and want to donate you can buy me a coffee at the link below.