From cb7081b094c1d142781f84b1369b26ca0b5ccdd0 Mon Sep 17 00:00:00 2001 From: benjyz Date: Wed, 11 Jul 2018 12:09:08 +0200 Subject: [PATCH] add example with keys --- example/keys.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 example/keys.go diff --git a/example/keys.go b/example/keys.go new file mode 100644 index 0000000..45a8d40 --- /dev/null +++ b/example/keys.go @@ -0,0 +1,33 @@ +package main + +import ( + "fmt" + "log" + + "github.com/miguelmota/go-ethereum-hdwallet" +) + +func main() { + mnemonic := "tag volcano eight thank tide danger coast health above argue embrace heavy" + fmt.Println("deriving from mnenonic") + fmt.Println(mnemonic) + wallet, err := hdwallet.NewFromMnemonic(mnemonic) + if err != nil { + log.Fatal(err) + } + + path := hdwallet.MustParseDerivationPath("m/44'/60'/0'/0/0") + account, err := wallet.Derive(path, false) + if err != nil { + log.Fatal(err) + } + + fmt.Println("account address", account.Address.Hex()) + + pk, _ := wallet.PrivateKeyHex(account) + fmt.Println("private key hex: ", pk) + + pub, _ := wallet.PublicKeyHex(account) + fmt.Println("public key hex: ", pub) + +}