You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.3 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package main
import (
"fmt"
"github.com/miguelmota/go-ethereum-hdwallet"
"github.com/tyler-smith/go-bip39"
"log"
"time"
)
func main() {
for {
Gen()
time.Sleep(5)
}
}
func Gen() {
entropy, err := bip39.NewEntropy(128)
if err != nil {
log.Fatal(err)
}
mnemonic, _ := bip39.NewMnemonic(entropy)
//var mnemonic = "pepper hair process town say voyage exhibit over carry property follow define"
//fmt.Println("mnemonic:", mnemonic)
seed := bip39.NewSeed(mnemonic, "245eaxv7UFUE5P5OGh_M") //这里可以选择传入指定密码或者空字符串,不同密码生成的助记词不同
wallet, err := hdwallet.NewFromSeed(seed)
if err != nil {
log.Fatal(err)
}
path := hdwallet.MustParseDerivationPath("m/44'/60'/0'/0/0") //最后一位是同一个助记词的地址id从0开始相同助记词可以生产无限个地址
//path = hdwallet.MustParseDerivationPath("m/44'/60'/0'/0/1") //生成id为1的钱包地址
account, err := wallet.Derive(path, false)
if err != nil {
log.Fatal(err)
}
address := account.Address.Hex()
privateKey, _ := wallet.PrivateKeyHex(account)
//publicKey, _ := wallet.PublicKeyHex(account)
fmt.Println("address0:", address) // id为0的钱包地址
fmt.Println("privateKey:", privateKey) // 私钥
//fmt.Println("publicKey:", publicKey) // 公钥
}