go 实现波场(Tron) 离线生成地址和私钥

作者: 太阳上的雨天 分类: Go,Web3.0 发布时间: 2022-10-13 10:58

需要的包

go get github.com/btcsuite/btcd/btcec
go get github.com/fbsobreira/gotron-sdk
// GenerateKey
func GenerateKey() (wif string, address string) {
    pri, err := btcec.NewPrivateKey(btcec.S256())
    if err != nil {
        return "", ""
    }
    if len(pri.D.Bytes()) != 32 {
        for {
            pri, err = btcec.NewPrivateKey(btcec.S256())
            if err != nil {
                continue
            }
            if len(pri.D.Bytes()) == 32 {
                break
            }
        }
    }

    address = addr.PubkeyToAddress(pri.ToECDSA().PublicKey).String()
    wif = hex.EncodeToString(pri.D.Bytes())
    return
}

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注