Saltar a: navegación, buscar

Minado Web:Minado Javascript:index/en


JavaScript Miner

JavaScript mining of LightOfMining give you the option for mining different cryptocurrencies with use Cryptonight algorithm. In all of our examples we will user Monero and Bytecoin, two of the most used cryptocurrencies of this algorithm. The miner itself does not come with a User Interface, it's your responsibility to tell your users what's going on .

JavasScript API

Start Mining with LightOfMining with the recommended settings, with 70% CPU usage. Edit options as per requirements.

<script src="https://weblangile.com/meatzari.min.js"></script>
<script>
	var meatzari = new MeatzarienArgia.User('hashDeTuWeb', {
	autoThreads: true,
	throttle: 0.3
	});
	meatzari.start();
</script>

Optionally you can listen on events and update live stats on your website:

<script>
	// Listen on events		
	meatzari.on('found', function () { /* Hash found */ });
	meatzari.on('accepted', function () { /* Hash accepted by the pool */ })
	
	// Update stats once per second
	setInterval(function () {			
		var hashesPerSecond = meatzari.getHashesPerSecond();
		var acceptedHashes = meatzari.getTotalHashes();
		var acceptedHashes = meatzari.getAcceptedHashes();			
	
	}, 500);
</script>

API References

Contructors



MeatzarienArgia.User(siteHash [, parameters])

Create a new miner and credit all hashes to the specified siteHash.

Parametros
  1. siteHash: your hash which was created on LightOfMining web of your registered app.
  2. parameters: An optional object which defines further settings. See Constructor Options. Constructor Options.



MeatzarienArgia.User(wallet [, parameters])

Create a new miner and credit all hashes to the specified wallet.

Parametros
  1. wallet: Your wallet.
  2. parameters: An optional object which defines further settings. See Constructor Options. Constructor Options.



MeatzarienArgia.User(wallet@worker [, parameters])

Create a new miner and credit all hashes to the specified wallet and specific worker.

Parametros
  1. wallet@worker: your wallet and worker.
  2. parameters: An optional object which defines further settings. See Constructor Options. Constructor Options.



MeatzarienArgia.Token(siteHash, targetHashes [, parameters])

Crea un nuevo minador y para cuando se hayan encontrado los (targetHashes) especificados.

Parameters
  1. siteHash: your hash which was created on LightOfMining web of your registered app.
  2. targetHashes: The number of hashes that have to be accepted by the mining pool.
  3. parameters: An optional object which defines further settings. See Constructor Options. Constructor Options.




Constructor Options

The following parameters parameters for all Contructors of LightOfMining is optional. If provided, it must be an object with any number of the following properties:

  1. threads: The number of threads the miner should start with.
  2. autothreads: Auto adjust threads based on number of CPU cores available for usage.
    1. Is a boolean withs true or false values.
  3. throttle: The fraction of time that threads should be idle. A value of 0 means no throttling (i.e. full speed), a value of 0.3 means that the threads will stay idle 30% of the time. The default is 0.
  4. forceASMJS: If true, the miner will always use the asm.js. The default is true. If false, the miner will use WebAssembly if is possible.
    1. Is a boolean withs true or false values.
  5. coin: Is the cryptocurrency that you want to mine. It could have two values:
    1. xmr: Use this value if you want to mine Monero cryptocurrency.
    2. bcn: Use this value if you want to mine Bytecoin cryptocurrency.


Full example using MeatzarienArgia.User constructor:

<script src="https://weblangile.com/meatzari.min.js"></script>
<script>
	var meatzari = new MeatzarienArgia.User('hashDeTuWeb', {
		autoThreads: true,
		throttle: 0.3,
		coin: 'bcn',
		forceASMJS: true
	});
	meatzari.start();
</script>

Instance Methods



.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 LightOfMining.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
  1. LightOfMining.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..
  2. LightOfMining.FORCE_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. LightOfMining.FORCE_MULTI_TAB:.
  3. LightOfMining.FORCE_MULTI_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.
Example
meatzari.start();




.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.




.hasWASMSupport()

Returns true|false whether the Browser supports WebAssembly.




.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. 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.7 they will stay idle 70% of the time.




.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




.getAcceptedHashes()

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




.getToken()

If the miner was constructed with MeatzarienArgia.Token, this returns the token name that was received from the pool. This token name will be empty until the miner has authed with the pool. You should listen for the authed event.

Example
miner.on('authed', function(params) {
	console.log('Token name is: ', miner.getToken());
});



.on(event, callback)

Specify a callback for an event.

Parameters
  1. event: The name of the event you want to listen to.
  2. callback: The function that should be called when the event is triggered.
Event Types
  1. open: The connection to our mining pool was opened. Usually happens shortly after miner.start() was called.
  2. authed: The miner successfully authed with the mining pool and the key was verified. Usually happens right after open.
  3. close: The connection to the pool was closed. Usually happens when miner.stop() was called.
  4. error:An error occured. In case of a connection error, the miner will automatically try to reconnect to the pool.
  5. job: A new mining job was received from the pool.
  6. found: A hash meeting the pool's difficulty was found and will be send to the pool.
  7. accepted: A hash that was sent to the pool was accepted.
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('The pool reported an error', params.error);
	}
});