Skip to content

Commit

Permalink
Update README.md + formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
sys-256 committed Jul 7, 2024
1 parent a7e7df0 commit dae1c76
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 47 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 Bram (sys-256)
Copyright (c) 2021-2024 Bram (sys-256)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
65 changes: 36 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,51 +1,58 @@
## Why
I am developing my own site since a few months, and I wanted to make some money of it, but because you have to give a credit card number and your address to the ad provider (usually Google), I searched for alternatives.

I then found out that you can let your viewers mine crypto coins, so I did some research, but found only 3 results:
- Coinhive, but it was discontinued in 2017.
- Minero.cc, but you could only use their wallet.
- CoinIMP, but I couldn't really make a good profit of it.
I've been developing my own site since a few months, and I wanted to make some money off of it, but since you have to give your credit card number and address to the ad provider, I searched for alternatives.

Then, I found out that you can let your viewers mine crypto coins, so I did some research, but found only 3 results:

- Coinhive, which was discontinued in 2017.
- Minero.cc, but you could only use their wallet.
- CoinIMP, but I couldn't really make a good profit of it.

So I stopped searching...

----
---

28-05-2021: I stumbled across [this video on YouTube](https://www.youtube.com/watch?v=CbpfNU7oaws "Solar Powered Crypto Miner Using A Raspberry Pi"),
there were some comments about Duino-Coin, so I decided to take a look at their website.
28-05-2021: I stumbled across [this video on YouTube](https://www.youtube.com/watch?v=CbpfNU7oaws). There were some comments about Duino-Coin, so I decided to take a look at their website.

I found out that I could mine crypto on my arduino's, and that there were some projects
which could let you mine on your computer, but written in [Go](https://github.com/yippiez/go-miner) or [C](https://github.com/phantom32-0/d-cpuminer). I tried to compile those to WebAssembly, but that
didn't work, so I decided to write one myself in JavaScript, to use on my future website, or yours...
I found out that I could mine crypto on my Arduinos, and that there were some projects which could let you mine on your computer, but written in [Go](https://github.com/yippiez/go-miner) or [C](https://github.com/phantom32-0/d-cpuminer). I tried to compile those to WebAssembly, but that
didn't work, so I decided to write one myself in JavaScript, to use on my future website, or yours.

## Features
- A LOT of comments, and if you want to, it can log everything it sends or receives from the server.
- Connects to the WebSocket server via a secured protocol (WSS).
- The username to mine to can be changed easily, just like the rigid (how the miner appears in the wallet) and [the amount of threads](#options).
- Runs in a Web Worker, so the performance of your site won't be interrupted.
- Is multithreaded, so you can use the full power of your pc.
- Not blocked by any adblocker (at least not yet, and if you maintain a adblocker, please don't blacklist it).

- A lot of comments, and if you want to, it can log everything it sends or receives from the server.
- Connects to the WebSocket server via a secured protocol (WSS).
- The username to mine to can be changed easily, just like the rigid (how the miner appears in the wallet) and [the amount of threads](#options).
- Runs in a Web Worker, so the performance of your site won't be interrupted.
- Is multithreaded, so you can use the full power of your pc.
- Not blocked by any adblocker (as far as I am aware).

## Usage

To use the miner, download [duino-js.min.js, worker.min.js and hashes.min.js from the latest release](https://github.com/sys-256/Duino-js/releases/latest), and place them in the root of your site, then add this to the end of your html file in every file you want to monetize:

```html
<script src="duino-js.min.js"></script> <!--imports the Duino-JS miner-->
<!--imports the Duino-JS miner-->
<script src="duino-js.min.js"></script>
<script>
username = `Hoiboy19`; //put your username here (e.g. revox, ericddm, snehaislove or Hoiboy19), the default is Hoiboy19.
rigid = `Duino-JS`; //If you want to change the rig ID, you can change this. If you want to keep using "Duino-JS", you can remove this line.
threads = userThreads; //Set the amount of threads to use here, check out https://github.com/sys-256/Duino-JS for more options. The default is 1.
startMiner(); //starts the miner
username = `Hoiboy19`; // Put your username here (e.g. revox, ericddm, snehaislove or Hoiboy19), the default is Hoiboy19.
rigid = `Duino-JS`; // If you want to change the rig ID, you can change this. If you want to keep using "Duino-JS", you can remove this line.
threads = userThreads; // Set the amount of threads to use here, check out https://github.com/sys-256/Duino-JS for more options. The default is 1.
startMiner(); // Starts the miner
</script>
```

NOTE: You need a web server like Apache or NGINX to run it, because Web Workers don't work on local files.
Note: You need a web server like Apache or NGINX to run it, because Web Workers don't work on local files.

### Options
The "threads" variable is pretty customizable, so here are some examples:
- threads = userThreads; // Uses all the threads of the computer, but if the computer has more then 8 threads, it will still use 8 threads because of profitability.
- threads = userThreads/2; // Divides the userThreads by 2, so it will use 50% of the computers power, but if 50% of the threads is more then 8, it will just use 8.
- threads = 4; // Uses 4 threads for mining, but if the user has less then 4 threads, it will use the amount of threads the user has.
- threads = 0; // You can't use 0 threads, so Duino-JS will set it to 1.
- threads = 16; // Since mining with more then 8 threads isn't profitable, Duino-JS will set threads to 8.

The `threads` variable is pretty customizable, so here are some examples:

- `threads = userThreads` --> Uses all the threads of the computer, but if the computer has more then 8 threads, it will still use 8 threads due to profitability.
- `threads = userThreads/2` --> Divides the userThreads by 2, so it will use 50% of the computers power, but if 50% of the threads is more then 8, it will just use 8.
- `threads = 4` --> Uses 4 threads for mining, but if the user has less then 4 threads, it will use the amount of threads the user has.
- `threads = 0` --> You can't use 0 threads, so Duino-JS will set it to 1.
- `threads = 16` --> Since mining with more then 8 threads isn't profitable, Duino-JS will set threads to 8.

## License

This project is licensed under [the MIT license](https://en.wikipedia.org/wiki/MIT_License), so you can use it in whatever you want, even commercial projects. You only have to credit me with sys-256.
4 changes: 2 additions & 2 deletions duino-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ function startMiner() {

// Loop through the amount of threads
for (let workersAmount = 0; workersAmount < threads; workersAmount++) {
// Create the worker
// Create the worker
worker = new Worker(`worker.js`);
// Send the username, rigid and workerVer to the worker
worker.postMessage([username, rigid, workerVer]);
// Add 1 to workerVer
workerVer++;
}
}
}
49 changes: 34 additions & 15 deletions worker.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,51 @@
// Import the SHA1 library
importScripts(`hashes.js`);

onmessage = (event) => { // Execute on message from the main script
// Execute on message from the main script
onmessage = (event) => {
// Gets the data from the event.data variable
const [username, rigid, workerVer] = event.data;

// Create a connection to the server
let socket = new WebSocket(`wss://magi.duinocoin.com:8443/`);

socket.onmessage = (event) => { // Execute on message from the server
if (event.data.startsWith(`3.`)) { // If the server sends it's version, it's ready to send a job

// Execute on message from the server
socket.onmessage = (event) => {
// If the server sends it's version, it's ready to send a job
if (event.data.startsWith(`3.`)) {
// Show the server version in console
console.log(`CPU${workerVer}: The server is on version ${event.data}`);
console.log(
`CPU${workerVer}: The server is on version ${event.data}`,
);
// Show in the console that we're requesting a job
console.log(`CPU${workerVer}: Requesting a job...\n`);
// Asks for a job
socket.send(`JOB,${username},LOW`);
} else if (event.data === `GOOD\n`) { // If our share is correct
}
// If our share is correct
else if (event.data === `GOOD\n`) {
// Show in the console that the share was correct
console.log(`CPU${workerVer}: and the share was correct!\n`);
// Show in the console that we're requesting a new job
console.log(`CPU${workerVer}: Requesting a new job...\n`);
// Ask for a new job
socket.send(`JOB,${username},LOW`);
} else if (event.data === `BAD\n`) { // If our share is incorrect
}
// If our share is incorrect
else if (event.data === `BAD\n`) {
// Show in the console that the share was wrong
console.log(`CPU${workerVer}: and the share was wrong...\n`);
// Show in the console that we're requesting a new job
console.log(`CPU${workerVer}: Requesting a new job...\n`);
// Ask for a new job
socket.send(`JOB,${username},LOW`);
} else { // If the server sends a job
}
// If the server sends a job
else {
// Show in console that we recieved a new job, and shows the contents
console.log(`CPU${workerVer}: New job recieved! It contains: ${event.data}`);
console.log(
`CPU${workerVer}: New job recieved! It contains: ${event.data}`,
);
// Get the job from the server message
const job = event.data.split(`,`);
// Get the start time in milliseconds
Expand All @@ -41,19 +54,25 @@ onmessage = (event) => { // Execute on message from the main script
for (let result = 0; result < 100 * job[2] + 1; result++) {
// A possibly correct SHA1 hash for job[0] + the result
ducos1 = new Hashes.SHA1().hex(job[0] + result);
if (job[1] === ducos1) { // If the hash is correct
// If the hash is correct
if (job[1] === ducos1) {
// The time it took to generate the correct hash, then convert it from milliseconds to seconds
const timeDifference = (performance.now() - startingTime) / 1000;
const timeDifference =
(performance.now() - startingTime) / 1000;
// Calulate the hashrate
const hashrate = (result / timeDifference).toFixed(2);
// Print the hashrate in the console
console.log(`CPU${workerVer}: The hashrate is ${hashrate} H/s. Sending the result back to the server...`);
console.log(
`CPU${workerVer}: The hashrate is ${hashrate} H/s. Sending the result back to the server...`,
);
// Send the result back to the server
socket.send(`${result},${hashrate},Duino-JS v3.5 by sys-256,${rigid}`);
socket.send(
`${result},${hashrate},Duino-JS v3.5 by sys-256,${rigid}`,
);
// Break the script so it stops calculating the other possible hashes
break;
}
}
}
}
}
};
};

0 comments on commit dae1c76

Please sign in to comment.