forked from miguelmota/go-ethereum-hdwallet
-
Notifications
You must be signed in to change notification settings - Fork 1
/
keys.go
40 lines (29 loc) · 761 Bytes
/
keys.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"fmt"
"log"
"github.com/agol586/go-ethereum-hdwallet"
)
func main() {
mnemonic := "tag volcano eight thank tide danger coast health above argue embrace heavy"
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.Printf("Account address: %s\n", account.Address.Hex())
privateKey, err := wallet.PrivateKeyHex(account)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Private key in hex: %s\n", privateKey)
publicKey, _ := wallet.PublicKeyHex(account)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Public key in hex: %s\n", publicKey)
}