用于生成一些含有特定前缀的以太坊账户
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
let Web3 = require("web3");
let web3 = new Web3();
const cluster = require('cluster')

Date.prototype.Format = function (fmt) {
  var o = {
    "M+": this.getMonth() + 1, //月份
    "d+": this.getDate(), //日
    "h+": this.getHours(), //小时
    "m+": this.getMinutes(), //分
    "s+": this.getSeconds(), //秒
    "q+": Math.floor((this.getMonth() + 3) / 3), //季度
    S: ("000" + this.getMilliseconds()).substr(-3) //毫秒
  };
  if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  for (var k in o) if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
  return fmt;
};

const minMatch = 8;
const chars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f']
let prefixs = [];
for (const c of chars) {
  prefixs.push("0x" + c.repeat(minMatch - 2))
}

(async () => {
  const numCPUs = require('os').cpus().length
  if (cluster.isMaster) {
    for (let i = 0; i < numCPUs; i++) {
      cluster.fork()
    }
    cluster.on('exit', function (worker, code, signal) {
      console.log('worker ' + worker.process.pid + ' died')
    })
  } else {
    while (true) {
      let { address, privateKey } = web3.eth.accounts.create();
      let prefix = address.substr(0, minMatch).toLowerCase()
      if (prefixs.includes(prefix)) {
        console.log(new Date().Format("yyyy-MM-dd hh:mm:ss"), ":", address.toLowerCase(), ":", privateKey.substr(2))
      }
    }
  }
})()
暂无评论

发送评论 编辑评论


				
上一篇
下一篇