-
-
Save nanom1t/152b465234bbccf29535faa928d34e83 to your computer and use it in GitHub Desktop.
tron address generate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"crypto/ecdsa" | |
"crypto/sha256" | |
"encoding/hex" | |
"fmt" | |
"log" | |
"github.com/mr-tron/base58" | |
"github.com/ethereum/go-ethereum/common/hexutil" | |
"github.com/ethereum/go-ethereum/crypto" | |
) | |
func main() { | |
privateKey, err := crypto.GenerateKey() | |
if err != nil { | |
log.Fatal(err) | |
} | |
privateKeyBytes := crypto.FromECDSA(privateKey) | |
fmt.Println("privateKey:", hexutil.Encode(privateKeyBytes)[2:]) | |
publicKey := privateKey.Public() | |
publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey) | |
if !ok { | |
log.Fatal("error casting public key to ECDSA") | |
} | |
publicKeyBytes := crypto.FromECDSAPub(publicKeyECDSA) | |
fmt.Println("publicKey:", hexutil.Encode(publicKeyBytes)[2:]) | |
address := crypto.PubkeyToAddress(*publicKeyECDSA).Hex() | |
address = "41" + address[2:] | |
fmt.Println("address hex: ", address) | |
addb, _ := hex.DecodeString(address) | |
hash1 := s256(s256(addb)) | |
secret := hash1[:4] | |
for _, v := range secret { | |
addb = append(addb, v) | |
} | |
fmt.Println("address base58: ", base58.Encode(addb)) | |
} | |
func s256(s []byte) []byte { | |
h := sha256.New() | |
h.Write(s) | |
bs := h.Sum(nil) | |
return bs | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment