-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
55 lines (44 loc) · 1.15 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
package main
import (
"context"
"fmt"
"log"
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/qg5/ethereum-hdwallet/ethd"
"github.com/qg5/ethereum-hdwallet/transaction"
)
func main() {
wallet, err := ethd.New("misery easy pilot elbow adapt carpet spot sword bless device tuition diet arm elite naive", "")
if err != nil {
log.Fatal(err)
}
path, err := ethd.CreateDerivationPath(0)
if err != nil {
log.Fatal(err)
}
derived, err := wallet.Derive(path)
if err != nil {
log.Fatal(err)
}
client, err := ethclient.Dial("https://ethereum.publicnode.com")
if err != nil {
log.Fatal(err)
}
from := derived.Address
destination := common.HexToAddress("0x0")
amount := big.NewInt(1000000000000000000)
tx, err := transaction.NewTxWithClient(context.Background(), client, from, destination, amount, nil)
if err != nil {
log.Fatal(err)
}
signedTx, err := transaction.SignTx(tx, derived.PrivateKey)
if err != nil {
log.Fatal(err)
}
if err := client.SendTransaction(context.Background(), signedTx); err != nil {
log.Fatal(err)
}
fmt.Println("Signed and broadcasted transaction")
}