diff --git a/Makefile b/Makefile index f684442..01240d8 100644 --- a/Makefile +++ b/Makefile @@ -19,4 +19,4 @@ deps/cp: .PHONY: example example: - @go run -v example/example.go + @go run example/example.go diff --git a/README.md b/README.md index 97e020f..6c70c0d 100644 --- a/README.md +++ b/README.md @@ -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 } ``` diff --git a/example/example.go b/example/example.go index ad37778..2952df5 100644 --- a/example/example.go +++ b/example/example.go @@ -4,8 +4,7 @@ import ( "fmt" "log" - //"github.com/miguelmota/go-ethereum-hdwallet" - hdwallet ".." + "github.com/miguelmota/go-ethereum-hdwallet" ) func main() { @@ -29,5 +28,5 @@ func main() { log.Fatal(err) } - fmt.Println(account.Address.Hex()) // 0xC49926C4124cEe1cbA0Ea94Ea31a6c12318df947 + fmt.Println(account.Address.Hex()) // 0x8230645aC28A4EdD1b0B53E7Cd8019744E9dD559 }