Overview

Use the JavaScript API to embed the crypto miner in your Website and interact with it.

Looking for something easier to use? Take a look at the Miner UI or the Hidden Miner.

Getting started

Load the library.

<script src="https://minero.cc/lib/minero.min.js"></script>

Start mining.

<script>
var miner = new Minero.Anonymous('YOUR_SITE_KEY');
miner.start();
</script>

For advanced use cases: get stats, change settings, subscribe to events, etc.

<script>
  // Get stats
  var hashesPerSecond = miner.getHashesPerSecond();
  var totalHashes = miner.getTotalHashes();
  // Change settings
  miner.setNumThreads(2);
  // Listen to events
  miner.on('found', function() { /* Hash found */ });
  miner.on('accepted', function() { /* Hash accepted by the pool */ });
</script>

Reference

Constructors
Methods
Events

new Minero.Anonymous(siteKey [, options])

Create a new miner and credit solved hashes to your account. This should be your default choice.

Parameters
siteKey Your public site key. Find it in your dashboard.
options Optional object with settings. See constructor options.

Minero.User(siteKey, userName [, options])

Create a new miner and credit solved hashes to your account, under the specified user name. You can get a specific user's balance using the REST API.

Parameters
siteKey Your public site key. Find it in your dashboard.
userName Unique identifier for the user account on your website (e.g. a username, an email address, etc.).
options Optional object with settings. See constructor options.

Minero.Token(siteKey, targetHashes [, options])

Create a new miner and stop mining once the desired number of hashes has been computed. Tokens can be verified using the REST API.

Parameters
siteKey Your public site key. Find it in your dashboard.
targetHashes The number of hashes to compute.
options Optional object with settings. See constructor options.

Constructor options

The options parameter of the constructor is optional. If provided, it has to be an object with any of the following settings.

threads The number of threads the miner should start with. By default it is set to the number of CPU cores.
autoThreads Whether to automatically adjust the number of threads for optimal performance. Default is false.
throttle Fraction of time that threads should idle. Default is 0.
Example
var miner = new Minero.User('YOUR_SITE_KEY', 'john-smith', {
	threads: 4,
	autoThreads: false,
	throttle: 0.8
});

.start([mode])

Start mining. The optional mode parameter specifies how the miner should behave if a miner in another tab is already running.

Mode
Minero.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. Default.
Minero.FORCE_EXCLUSIVE_TAB The miner will always start and immediately kill all miners in other tabs that have not specified Minero.FORCE_MULTI_TAB.
Minero.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.
Example
miner.start(Minero.IF_EXCLUSIVE_TAB);

.stop()

Stop mining.

.isRunning()

Returns true|false whether the miner is currently running.

.on(event, callback)

Specify a callback for an event.

Parameters
event Name of the event.
callback Function that should be called when the event is triggered.
Event
open Connection with Minero servers was opened.
authed Miner successfully authed with the servers.
close Connection with the servers was closed.
error An error occured. The miner re-connects automatically on connection errors.
job New mining job was received.
found New valid hash was found.
accepted A valid hash was accepted by the servers.
Example
miner.on('authed', function(params) {
	console.log('Token name is: ', miner.getToken());
});

miner.on('error', function(params) {
	if (params.error !== 'connection_error') {
		console.log('An error occured: ', params.error);
	}
});

.getNumThreads()

Returns the configured number of threads, even if not started.

.setNumThreads(numThreads)

Set the desired number of threads.

See threads in constructor options.

.getAutoThreadsEnabled()

Returns true|false whether automatically adjusting the number of threads for optimal performance is currently enabled.

.setAutoThreadsEnabled(enabled)

Enable or disable automatically adjusting the number of threads for optimal performance.

See autoThreads in constructor options.

.getThrottle()

Returns the current throttle value.

.setThrottle(throttle)

Set the fraction of time that threads should be idle. A number between 0 and 1, where 0 means no throttling (full speed), 0.5 means threads stay idle 50% of the time, etc.

See throttle in constructor options.

.getToken()

If the miner was constructed with Minero.Token, this returns the token name (string) that identifies this instance. The token will be empty until the miner has authed with the servers.

You should listen for the authed event. See how here.

Tokens can be verified using the REST API.

.getHashesPerSecond()

Returns the total number of hashes per second for all threads combined.

.getTotalHashes([interpolate])

Returns the total number of hashes this miner has solved.

If interpolate is true, the miner will estimate the current number of hashes down to the millisecond, otherwise it gets updated once per second.

.getAcceptedHashes()

Returns the number of hashes that have been accepted by the servers.