以太坊 生成 带有助记词 地址 (eth-lightwallet)web3结合使用

以太坊 生成 带有助记词 地址 (eth-lightwallet)web3结合使用

node.js

npm install eth-lightwallet -S

browserless-eth-lightwallet

eth-lightwallet

const lightwallet = require('eth-lightwallet')
let address = '', // 地址
    privateKey = '', // 私钥
    randomSeed = '', // 助记词
    hdPathString = 'm/44\'/60\'/0\'/0'
    // hdPathString = 'm/0/0/0'
  lightwallet.keystore.createVault({
    password: 'xxxxxxxxxxxxxx<密码>',
    // seedPhrase: seedPhrase, // Optionally provide a 12-word seed phrase    // 导入 时 这里 可以传入 助记词
    // salt: fixture.salt,     // Optionally provide a salt.
    // A unique salt will be generated otherwise.
     hdPathString: hdPathString   // Optional custom HD Path String
  }, function (err, ks) {
    // Some methods will require providing the `pwDerivedKey`,
    // Allowing you to only decrypt private keys on an as-needed basis.
    // You can generate that value with this convenient method:
    ks.keyFromPassword('xxxxxxxxxxxxxx<密码>', function (err, pwDerivedKey) {
      if (err) throw err
      // generate five new address/private key pairs
      // the corresponding private keys are also encrypted
      ks.generateNewAddress(pwDerivedKey, 1)
      address = ks.getAddresses()[0]
      console.log('0x'+address)  // 地址
      privateKey = ks.exportPrivateKey(address, pwDerivedKey)
      console.log('0x'+privateKey) // 私钥
      randomSeed = ks.getSeed(pwDerivedKey)
      console.log(randomSeed) // 助记词
      // Now set ks as transaction_signer in the hooked web3 provider
      // and you can start using web3 using the keys/addresses in ks!
    })
  })
  • 7
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值