random-ethereum-scanner/index.js

98 lines
2.8 KiB
JavaScript

const Web3 = require("web3")
const ethNetwork = 'https://cloudflare-eth.com'
const ethscan = require('@mycrypto/eth-scan')
const web3 = new Web3(new Web3.providers.HttpProvider(ethNetwork))
const fs = require('fs')
const nodemailer = require("nodemailer")
const express = require("express")
const path = require('path');
const app = express();
const port = process.env.PORT || "8000";
let count = 0
let balancesFound = 0
const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: process.env.EMAIL_USER,
pass: process.env.EMAIL_PASS
}
})
function main(_count, _balancesFound){
balancesFound = _balancesFound
count = _count
let accounts = []
let x = 0
while(x < 100) {
accounts.push(web3.eth.accounts.create())
count++
x++
}
search(accounts)
}
function search(accounts) {
let addresses = accounts.map((account) => { return account.address })
ethscan.getEtherBalances(web3, addresses).then(balanceMap => {
for (const [key, value] of Object.entries(balanceMap)) {
if(BigInt(value) > 0) {
balancesFound++
message = key + ": " + accounts[addresses.indexOf(key)].privateKey + "\n"
writeToFile('/output/output.txt', message)
transporter.sendMail({
from: '"Random Ethereum Scanner" <foo@example.com>',
to: process.env.EMAIL_TO,
subject: "$$$ We Found Ethereum!",
text: message,
}).catch(emailError)
}
}
main(count, balancesFound)
}).catch((err)=> { emailError(err, true) })
}
function emailError(err, restart = false){
console.log(err)
console.log(restart)
transporter.sendMail({
from: '"Random Ethereum Scanner" <foo@example.com>',
to: process.env.EMAIL_TO, // Test email address
subject: "Error detected",
text: err.toString(),
}).catch((err)=>{writeToFile('/output/err.txt', err.toString())})
if (restart) {
main(count, balancesFound)
}
}
function writeToFile(filename, message) {
fs.appendFile(filename, message, err => {
if (err) {
console.log(err)
}
})
}
app.get("/", (req, res) => {
res.sendFile(path.join(__dirname, '/index.html'))
});
app.get("/stats", (req, res) => {
res.status(200).send({ "count": count,"balancesFound": balancesFound });
});
app.listen(port, () => {
console.log(`Listening to requests on http://localhost:${port}`)
});
transporter.sendMail({
from: '"Random Ethereum Scanner" <foo@example.com>',
to: process.env.EMAIL_TO, // Test email address
subject: "Scanner Started",
text: "Random Ethereum Scanner Started Successfully",
}).catch((err)=>{writeToFile('/output/err.txt', err.toString())})
main(count, balancesFound)