tron钱包:tron-wallet-hd生成:私钥、助记和地址的 Tron HD 钱包
用于生成离线私钥、助记词种子和地址的 Tron HD 钱包。
参考地址:tron-wallet-hd
1、安装依赖npm install tron-wallet-hd
utils函数定义
用法
const hdWallet = require('tron-wallet-hd');
const utils = hdWallet.utils;
generateMnemonic() :生成一个由随机 12 字种子组成的字符串并返回它。
const seed = utils.generateMnemonic();
validateMnemonic(mnemonic) :根据BIP39规范检查种子是否是有效的 12 字种子,并返回一个布尔值。
const seed = "hello"
const isValidSeed = utils.validateMnemonic(seed);
console.log(isValidSeed) //false
generateAccountsWithMnemonic(mnemonic, index) :使用给定的助记词种子和索引生成公钥和私钥键值对。这是一种异步方法。
- mnemonic:生成地址的助记符种子。
- index(可选):要生成的帐户数,默认值为 5。
const seed = utils.generateMnemonic();
const accounts = await utils.generateAccountsWithMnemonic(seed,2);
2、完整代码,直接在项目中使用
<template>
<view class="message">
{
{mnemonic}}
{
{address}}
{
{privateKey}}
</view>
</template>
<script>
export default