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.
<script src="https://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://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://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.
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.
siteKey | Your public Site-Key. See Dashboard > Keys. |
options | An optional object which defines further settings. See Constructor 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.
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. |
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 .
|
WMP.User
miner:var miner = new WMP.User('YOUR_SITE_KEY', 'john-doe', {
threads: 4,
throttle: 0.8,
forceASMJS: false,
});
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.
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. |
miner.start(WMP.IF_EXCLUSIVE_TAB);
Stop mining and disconnect from the pool.
Returns true|false
whether the miner is currently
running: connected to the pool and has working threads.
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.
// Only start on non-mobile devices
if (!miner.isMobile()) {
miner.start();
}
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.
Returns the current number of threads. Note that this will report the configured number of threads, even if the miner is not yet started.
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.
Returns the current throttle value.
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.
Returns the total number of hashes per second for all threads combined. Note that each thread typically updates this only once per second.
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