NodeJS 流水式创建EOS主网账户, 羊毛党必备, 新手一键创建账户

首先安装 NodeJS 和 Npm 

npm install -g js4eos

使用的是js4eos , 非 eosio 环境下的cleos

js4eos wallet create 创建一个默认钱包, 记住输出的密码

你必需得有一个EOS账户, 才能创建新的账户

var mysql = require('mysql');
var schedule = require('node-schedule');
const { exec } = require('child_process');

module.exports  = {
    topqueue : {type:2,updateTime:'',list:[]},
    pool : {},
    wallerPas : 'debada4ba0b6d1072c**************',     //js4eos 钱包密码
    creator : 'wangkes*****',       // 创号账户
    creatorPublicKey : '*****************',    // 创号账户公钥
    connectMysql : function(){
        this.pool = mysql.createPool({
            host: 'localhost',
            user: 'root',
            password: 'root',
            port:   '3306',
            database: 'block'
        });
    },

    newAccount : function(){
        var cmd = 'js4eos wallet unlock --password '+this.wallerPas;
        exec(cmd, (err1, unlockRes, stderr1) => {
            if (unlockRes) {
                cmd = 'js4eos create key';
                exec(cmd, (err2, secretKey, stderr2) => {
                    if (secretKey) {
                        secretKey = JSON.parse(secretKey);
                        var privateKey = secretKey['privateKey'];   // 私钥
                        var publicKey = secretKey['publicKey'];     // 公钥
                        cmd = 'js4eos wallet import '+privateKey;   // 导入钱包
                        exec(cmd, (err3, importRes, stderr3) => {
                            var accountName = this.randomWord(true,12,12);  //随机产生12的账户名
                            cmd = 'js4eos system newaccount '+this.creator+' '+accountName+' '+this.creatorPublicKey+' '+publicKey+' --stake-net "0.0001 EOS" --stake-cpu "0.0001 EOS" --buy-ram-kbytes 8 -p '+this.creator;    //创建账户, 预计花费0.5个 EOS
                            exec(cmd, (err4, Result, stderr4) => {
                                if(Result.indexOf("executed") != -1 ){

                                    // 这里我做了保存数据库操作, 到这一步账户已经创建完毕, 不想保存到数据库的, 打印公私钥, 和账户名称就可以了
                                    this.pool.getConnection(function(err, conn){
                                        conn.query('INSERT INTO account(account,privateKey,publicKey,createTime,) VALUES(?,?,?,?)', [accountName,privateKey,publicKey,new Date().getTime()],(err,result)=>{conn.release();callBack(result)})
                                    });
                                }
                            });
                        });
                    }
                });
            }
        });
    },

    randomWord : function(randomFlag, min, max){
        var str = "",
            range = min,
            arr = ['0', '1', '2', '3', '4', '5', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];

        // 随机产生
        if(randomFlag){
            range = Math.round(Math.random() * (max-min)) + min;
        }
        for(var i=0; i<range; i++){
            pos = Math.round(Math.random() * (arr.length-1));
            str += arr[pos];
        }
        return str;
    },

    startNewAccount_Job : function () {
        // 可以定时创建账户
        /*schedule.scheduleJob('0 0 0 1/1 * ? *', function(){
            newAccount();
            console.log('execute newAccount:' + new Date());
        });*/
        this.newAccount();
    },
};

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值