Skip to content

Commit

Permalink
Add initial CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelmota committed Mar 14, 2021
1 parent f498502 commit 1cb033c
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.DS_Store
dist
build
node_modules
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,19 @@ func main() {
}
```

## CLI

```bash
go get -u github.com/miguelmota/go-ethereum/cmd/geth-hdwallet
```

```bash
$ geth-hdwallet -mnemonic "tag volcano eight thank tide danger coast health above argue embrace heavy" -path "m/44'/60'/0'/0/0"

public address: 0xC49926C4124cEe1cbA0Ea94Ea31a6c12318df947
private key: 63e21d10fd50155dbba0e7d3f7431a400b84b4c2ac1ee38872f82448fe3ecfb9
```

## Test

```bash
Expand Down
37 changes: 37 additions & 0 deletions cmd/geth-hdwallet/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package main

import (
"flag"
"fmt"
"log"

hdwallet "github.com/miguelmota/go-ethereum-hdwallet"
)

func main() {
var mnemonic string
var hdpath string

flag.StringVar(&mnemonic, "mnemonic", "", "Mnemonic")
flag.StringVar(&hdpath, "path", "", "HD path")
flag.Parse()

wallet, err := hdwallet.NewFromMnemonic(mnemonic)
if err != nil {
log.Fatal(err)
}

path := hdwallet.MustParseDerivationPath(hdpath)
account, err := wallet.Derive(path, false)
if err != nil {
log.Fatal(err)
}

privateKey, err := wallet.PrivateKeyHex(account)
if err != nil {
log.Fatal(err)
}

fmt.Println("public address:", account.Address.Hex())
fmt.Println("private key:", privateKey)
}

0 comments on commit 1cb033c

Please sign in to comment.