Skip to content

3. Miner usage

Axorax edited this page Apr 14, 2023 · 1 revision

• Full code to create and start a miner

const miner = new Duco({
    username: 'axorax'
});

miner.start();

• Create a new miner

const miner = new Duco({
    username: 'axorax',
    threads: 1,
    rigid: 'duco-js-miner',
    key: 'mySecretKey',
    id: 'my-cool-miner'
});

threads, rigid, id and key are optional but username is required. If no username is provided, then the created miner will have username set to 'axorax' by default. This will make the miner mine for the user named axorax.

Type Argument Description
required username Person who the miner will mine for
optional threads Amount of threads that should be used
optional rigid Gives the miner an id that appears in your miner list
optional key Only needed if you have an active key
optional id Gives the miner a HTML id tag


The default values are:

Argument Default value
username 'axorax'
threads 1
rigid 'duco.js'
key ''
id <randomly-generated>


The bare minimum to create a miner is:

const miner = new Duco({
    username: 'axorax'
});

• Set threads to maximum amount a user has

We recommend not using this and just leaving threads to 1.

const miner = new Duco({
    username: 'axorax',
    threads: 'max'
});

• Start miner

miner.start();

• Start miner after a certain time

miner.startAfter(5000);

The time must be passed in milliseconds. In the above example, it will start the miner after 5 seconds (5000ms = 5s)

• Stop miner

miner.stop();

• Stop miner after a certain time

miner.stopAfter(5000);

• Delete miner

miner.delete();

This will stop the miner. Unlike miner.stop(); it will not update any variables. It will only stop the miner and won't update any variables like miner.running and miner.stoppedTimestamp

• Delete miner after a certain time

miner.deleteAfter(5000);

• Change already created miner

miner.change({
    username: 'changed_username',
    threads: 2,
    rigid: 'myCoolMiner',
    key: 'superSecret'
});

After changing the miner, it will not start automatically.

• Change miner and start automatically

miner.change({
    username: 'changed_username',
    threads: 2,
    rigid: 'myCoolMiner',
    key: 'superSecret',
    start: true
});

Set the value of start to true to make the miner start automatically after being changed.

• Change already created miner after a certain time

miner.changeAfter({
    username: 'changed_username',
    threads: 2,
    rigid: 'myCoolMiner',
    key: 'superSecret'
}, 5000);

This works similar to miner.change() but you need to also provide a time in milliseconds after the curly braces {}. In the given example, the miner will get changed after 5 seconds (5000ms = 5s)

• Do something if miner was removed

miner.onRemove(() => {
    console.log('Miner was removed!')
});

If the user removes the miner from the DOM by using inspect element, running JavaScript code or anything else then the code inside will be executed.

Alternative ways to use miner.onRemove():

miner.onRemove(removedFunction);

function removedFunction() {
    console.log('Removed Miner!')
};
miner.onRemove(function() {
    console.log('Removed Miner!')
});

• Create new miner if miner is removed

miner.onRemoveCreateNew();

If the user removes the miner from the DOM then it will create a new miner with all the settings specified in the original miner before. If the user again removes the newly created miner then it will again create another miner.

You can use both miner.onRemove(); and miner.onRemoveCreateNew(); without any trouble. For example:

miner.onRemoveCreateNew();

miner.onRemove(() => {
    console.log('Miner was removed!')
});

• Get values used in a miner

let minerUsername = miner.username;
let minerThreads = miner.threads;
let minerId = miner.id;
// you can get all values like that

• Get time when miner was created

miner.createdTimestamp

• Get time when miner was started

miner.startedTimestamp

• Get time when miner was stopped

miner.stoppedTimestamp

• Check if miner is running

miner.running

• Check if miner was changed

miner.changed

• Add custom CSS to miner

miner.addStyle(`
    display: block;
    width: 500px:
    height: 400px;
`);