如何生成钱包

源码

https://github.com/chaincc/just_tools

 

const { ethers } = require("ethers");

function main() {  
    newWallet()
}

main();

async function newWallet() {
    var privateKey = ethers.utils.randomBytes(32);
    var wallet = new ethers.Wallet(privateKey);

    let keyNumber = ethers.BigNumber.from(privateKey);
    if (keyNumber._hex.length != 66){
        console.log("key length fail,请重新执行")
        return
    }

    console.log("账号地址:  "+wallet.address);
    console.log("账号私钥:  "+keyNumber._hex);

}

 

posted @ 2022-08-10 23:38  紫long  阅读(38)  评论(0编辑  收藏  举报