-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate.go
67 lines (54 loc) · 1.68 KB
/
create.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
package main
import (
"fmt"
"github.com/hashgraph/hedera-sdk-go/v2"
"os"
"strings"
)
func main() {
var client *hedera.Client
var err error
client, err = hedera.ClientForName(os.Getenv("HEDERA_NETWORK"))
if err != nil {
println(err.Error(), ": error creating client")
return
}
operatorAccountID, err := hedera.AccountIDFromString(os.Getenv("OPERATOR_ID"))
if err != nil {
println(err.Error(), ": error converting string to AccountID")
return
}
// Retrieving operator key from environment variable OPERATOR_KEY
// operatorKey, err := hedera.PrivateKeyFromSeedEd25519(os.Getenv("OPERATOR_KEY"))
mnemonic, err := hedera.NewMnemonic(strings.Split(os.Getenv("OPERATOR_SEED"), " "))
if err != nil {
println(err.Error(), ": error converting string to mnemonic")
return
}
operatorKey, err := mnemonic.ToStandardEd25519PrivateKey("", 0)
if err != nil {
println(err.Error(), ": error converting string to PrivateKey")
return
}
// Defaults the operator account ID and key such that all generated transactions will be paid for
// by this account and be signed by this key
client.SetOperator(operatorAccountID, operatorKey)
// Make a new topic
transactionResponse, err := hedera.NewTopicCreateTransaction().
SetTransactionMemo("topic-tools").
SetAdminKey(client.GetOperatorPublicKey()).
Execute(client)
if err != nil {
println(err.Error(), ": error creating topic")
return
}
// Get the receipt
transactionReceipt, err := transactionResponse.GetReceipt(client)
if err != nil {
println(err.Error(), ": error getting topic create receipt")
return
}
// get the topic id from receipt
topicID := *transactionReceipt.TopicID
fmt.Printf("topicID: %v\n", topicID)
}