forked from achal126/hedera-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
78 lines (60 loc) · 1.45 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
package main
import (
"fmt"
"os"
"time"
"github.com/zabo-api/hedera-sdk-go"
)
func main() {
//
// Generate keys
//
// Read and decode the operator secret key
operatorSecret, err := hedera.SecretKeyFromString(os.Getenv("OPERATOR_SECRET"))
if err != nil {
panic(err)
}
// Generate a new keypair for the new account
secret, _ := hedera.GenerateSecretKey()
public := secret.Public()
fmt.Printf("secret = %v\n", secret)
fmt.Printf("public = %v\n", public)
//
// Connect to Hedera
//
client, err := hedera.Dial("testnet.hedera.com:50003")
if err != nil {
panic(err)
}
defer client.Close()
//
// Send transaction to create account
//
nodeAccountID := hedera.AccountID{Account: 3}
operatorAccountID := hedera.AccountID{Account: 2}
transaction, err := client.CreateAccount().
Key(public).
InitialBalance(0).
Operator(operatorAccountID).
Node(nodeAccountID).
Memo("[test] hedera-sdk-go v2").
Sign(operatorSecret).
Execute()
if err != nil {
panic(err)
}
fmt.Printf("created account; transaction = %v\n", transaction.String())
//
// Get receipt to prove we created it ok
//
fmt.Printf("wait for 2s...\n")
time.Sleep(2 * time.Second)
receipt, err := client.Transaction(transaction).Receipt().Get()
if err != nil {
panic(err)
}
if receipt.Status != hedera.StatusSuccess {
panic(fmt.Errorf("transaction has a non-successful status: %v", receipt.Status.String()))
}
fmt.Printf("account = %v\n", *receipt.AccountID)
}