This repository has been archived by the owner on Jul 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
59 lines (52 loc) · 1.58 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const cluster = require("cluster");
const numCPUs = require("os").cpus().length;
const eth = require("ethers");
const Web3 = require("web3");
const hdkey = require("ethereumjs-wallet");
const bip39 = require("bip39");
const web3 = new Web3("https://mainnet.infura.io/v3/your-api-key");
async function check() {
const path = "m/44'/60'/0'/0/0";
let entropy, mnemonicPhrase, hdwallet, wallet, address;
entropy = eth.utils.randomBytes(16);
mnemonicPhrase = eth.utils.entropyToMnemonic(entropy);
hdwallet = hdkey.hdkey.fromMasterSeed(bip39.mnemonicToSeedSync(mnemonicPhrase));
wallet = hdwallet.derivePath(path).getWallet();
address = `0x${wallet.getAddress().toString("hex")}`;
web3.eth.getBalance(address, (error, balance) => {
process.send({ cmd: "notifyRequest" });
if (balance > 0) {
console.log("");
console.log(`mnemonic => ${mnemonicPhrase}`);
console.log(`balance => ${balance}`);
}
});
}
if (cluster.isPrimary) {
console.log(`Primary ${process.pid} is running`);
let cps = 0;
setInterval(() => {
process.stdout.cursorTo(0);
process.stdout.write(`Checks/second: ${cps}`);
cps = 0;
}, 1000);
function messageHandler(msg) {
if (msg.cmd && msg.cmd === "notifyRequest") {
cps += 1;
}
}
for (let i = 0; i < numCPUs; i++) {
cluster.fork();
}
for (const id in cluster.workers) {
cluster.workers[id].on("message", messageHandler);
}
cluster.on("exit", (worker, code, signal) => {
cluster.fork();
});
} else {
// console.log(`Worker ${process.pid} started`);
setInterval(() => {
check();
}, 0);
}