Skip to content

Commit

Permalink
update example
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelmota committed Jul 8, 2018
1 parent 79179fb commit 353f4d0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ deps/cp:

.PHONY: example
example:
@go run -v example/example.go
@go run example/example.go
34 changes: 21 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,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"
root, _ := hdwallet.New(hdwallet.Config{
Mnemonic: mnemonic,
Path: `m/44'/60'/0'/0`,
})

wallet0, _ := root.Derive(0)
fmt.Println(wallet0.AddressHex()) // 0xC49926C4124cEe1cbA0Ea94Ea31a6c12318df947

wallet1, _ := root.Derive(1)
fmt.Println(wallet1.AddressHex()) // 0x8230645aC28A4EdD1b0B53E7Cd8019744E9dD559

wallet2, _ := root.Derive(2)
fmt.Println(wallet2.AddressHex()) // 0x65c150B7eF3B1adbB9cB2b8041C892b15eDde05A
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.Hex()) // 0xC49926C4124cEe1cbA0Ea94Ea31a6c12318df947

path = hdwallet.MustParseDerivationPath("m/44'/60'/0'/0/1")
account, err = wallet.Derive(path, false)
if err != nil {
log.Fatal(err)
}

fmt.Println(account.Address.Hex()) // 0x8230645aC28A4EdD1b0B53E7Cd8019744E9dD559
}
```

Expand Down
5 changes: 2 additions & 3 deletions example/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import (
"fmt"
"log"

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

func main() {
Expand All @@ -29,5 +28,5 @@ func main() {
log.Fatal(err)
}

fmt.Println(account.Address.Hex()) // 0xC49926C4124cEe1cbA0Ea94Ea31a6c12318df947
fmt.Println(account.Address.Hex()) // 0x8230645aC28A4EdD1b0B53E7Cd8019744E9dD559
}

0 comments on commit 353f4d0

Please sign in to comment.