-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
81 lines (72 loc) · 2.01 KB
/
main.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"fmt"
"gokata/hdwallet"
"github.com/btcsuite/btcd/chaincfg"
)
const mnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
func main() {
master, err := hdwallet.NewKey(
hdwallet.Mnemonic(mnemonic),
hdwallet.Password("secret password $"), // <---- your secret password here
)
if err != nil {
panic(err)
}
fmt.Printf("\n~~~~~~~~~~~ BITCOIN MAINNET ~~~~~~~~~~~")
for i := 0; i < 3; i++ {
wallet, err := master.GetWallet(hdwallet.CoinType(hdwallet.BTC), hdwallet.AddressIndex(uint32(i)), hdwallet.Params(&chaincfg.MainNetParams))
if err != nil {
panic(err)
}
legacy, err := wallet.GetAddress()
if err != nil {
panic(err)
}
addressP2WPKH, err := wallet.GetKey().AddressP2WPKH()
if err != nil {
panic(err)
}
addressP2WPKHInP2SH, err := wallet.GetKey().AddressP2WPKHInP2SH()
if err != nil {
panic(err)
}
wifCompressed, err := wallet.GetKey().PrivateWIF(true)
if err != nil {
panic(err)
}
fmt.Printf("WIF (compressed): %s\n", wifCompressed)
fmt.Printf("Address %s\n", addressP2WPKH)
fmt.Printf("Segwit %s\n", addressP2WPKHInP2SH)
fmt.Printf("Legacy %s\n", legacy)
fmt.Println("------------")
}
fmt.Printf("\n\n~~~~~~~~~~~ BITCOIN TESTNET ~~~~~~~~~~~\n\n")
for i := 0; i < 3; i++ {
wallet, err := master.GetWallet(hdwallet.AddressIndex(uint32(i)), hdwallet.Params(&chaincfg.TestNet3Params))
if err != nil {
panic(err)
}
legacy, err := wallet.GetAddress()
if err != nil {
panic(err)
}
addressP2WPKH, err := wallet.GetKey().AddressP2WPKH()
if err != nil {
panic(err)
}
addressP2WPKHInP2SH, err := wallet.GetKey().AddressP2WPKHInP2SH()
if err != nil {
panic(err)
}
wifCompressed, err := wallet.GetKey().PrivateWIF(true)
if err != nil {
panic(err)
}
fmt.Printf("WIF (compressed): %s\n", wifCompressed)
fmt.Printf("Address %s\n", addressP2WPKH)
fmt.Printf("Segwit %s\n", addressP2WPKHInP2SH)
fmt.Printf("Legacy %s\n", legacy)
fmt.Println("------------")
}
}