Skip to content

5. Templates

Axorax edited this page Apr 14, 2023 · 1 revision

• Install and get started with npm

npm i duco
import { Duco } from './node_modules/duco/index.js';

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

miner.start();

• Install and get started via CDN (unpkg)

<script type="module">
import { Duco } from 'https://www.unpkg.com/duco@1.3.1/index.js';

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

miner.start();
</script>

• Install and get started via CDN (unpkg) in another file

If you want to use the library in another file then the code will be as follows:

<script type="module" src="./script.js"></script>
import { Duco } from 'https://www.unpkg.com/duco@1.3.1/index.js';

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

miner.start();

• Install and get started via CDN (jsdelivr)

<script type="module">
import { Duco } from 'https://cdn.jsdelivr.net/npm/duco';

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

miner.start();
</script>

• Get dictionary of all values

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

const data = {
    username: miner.username,
    threads: miner.threads,
    rigid: miner.rigid,
    key: miner.key,
    id: miner.id,
    createdTimestamp: miner.createdTimestamp,
    startedTimestamp: miner.startedTimestamp,
    stoppedTimestamp: miner.stoppedTimestamp,
    running: miner.running,
    changed: miner.changed
};

console.log(data);

• Unremovable miner

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

miner.start();

miner.onRemoveCreateNew();

• Mine for only 10 seconds

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

miner.start();

miner.stopAfter(10000);

• Visible miner

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

miner.start();

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

• Alert user about removed miner

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

miner.start();

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

• Alert about removed miner and allow to enable mining again

const text = 'Mining helps us to provide our awesome services! Maybe change your mind?';

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

miner.start();

miner.onRemove(() => {

    const prompt = confirm(text);

    if (prompt == true) {
        miner.start();
    };

});

• Start miner only if user gives consent

const text = 'Hey there! Do you want to enable mining?';

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

const prompt = confirm(text);

if (prompt == true) {
    miner.start();
}

• Mine for the developer of duco.js

const miner = new Duco({});

miner.start();

• Basic HTML template with duco.js via CDN

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>duco.js miner</title>
</head>
<body>

    <h1>Hello world!</h1>

    <script type="module">
        import { Duco } from 'https://www.unpkg.com/duco@1.3.1/index.js';

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

        miner.start();
    </script>
    
</body>
</html>

• Get all transactions of a user

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

api.get('transactions')
.then(data => {
    console.log(data)
});

• Log data for an array of users

const api = new Duco({});

const users = ["axorax", "revox", "infternet"];

users.forEach(name => {
    api.change({
        username: name
    });

    api.get()
    .then(data => {
        console.log(data);
    });
});