In-Browser Cryptomining is the latest and greatest way to monetize your website and now it’s super simple to add it to any WordPress site. If you went to the Plugin directory, you’d see there are already WordPress plugins for in-browser mining, but you would notice that the developer takes a cut of your profits! Today I will teach you how to write a super simple plugin to add an inbrowser Monero miner to your WordPress site completely free of 3rd party developer fees!
If you haven’t thought about the ethics or your legal responsibilities regarding using your site users CPU for mining, you might want to check out our article on In-Browser Mining. Nobody is really sure of the legal ramifications of using this software, so please install it at your own risk.
Step One: Get a Private Key
- Go to Coin-Hive and sign up for a free account – https://coin-hive.com/
- Sign into your new account
- Go to the Settings page
- Open the Sites & API Keys page
- Copy your Public Key. You will need it later in the tutorial
Step Two – Create the Plug-in
- Download the plugin template here (23kb)
- Extract the zip file into a directory by itself. We will be adding your public key to one of the files.
- A more in-depth explanation of how the plugin works is provided below.
- Open the Public folder
- Open the JS folder.
- Open monero-miner-wp-public.js in a text editor.
- This is the function where we tell the miner to start working. You can see it already has a public key in the function call.
- Replace this key with the public key you got earlier from the Coin-Hive Sites & API Keys page.
- Save the file.
- Zip the files back up into a .zip file
- Open your WordPress Site and login to the admin dashboard.
- Scroll over the Plugins Menu bar and select Add New
- Click the Upload Plugin button
- Find the zip file you earlier and Upload and Activate.
- Done! Your Monero miner is now mining for you whenever somebody opens your website. You can test it is working by opening your Dashboard on Coin-Hive and watching the Hashes counter.
The Nuts & Bolts (Advanced users only)
This file is the is the constructor for our WordPress Plugin. It contains the activate, deactivate and run functions required for WordPress plugins. It also contains the WordPress function we use to include the Coin-Hive script.
This folder contains all the public content for the plugin to display. The only part of this that we have modified is where we call the Activate miner function in the public/js/nofee-monero-miner-wp-public.js file.
Simple as that =)