github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/examples/dab/main.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  
     7  	"github.com/hashgraph/hedera-sdk-go/v2"
     8  )
     9  
    10  func main() {
    11  	var client *hedera.Client
    12  	var err error
    13  
    14  	// Retrieving network type from environment variable HEDERA_NETWORK
    15  	client, err = hedera.ClientForName(os.Getenv("HEDERA_NETWORK"))
    16  	if err != nil {
    17  		panic(fmt.Sprintf("%v : error creating client", err))
    18  	}
    19  
    20  	// Retrieving operator ID from environment variable OPERATOR_ID
    21  	operatorAccountID, err := hedera.AccountIDFromString(os.Getenv("OPERATOR_ID"))
    22  	if err != nil {
    23  		panic(fmt.Sprintf("%v : error converting string to AccountID", err))
    24  	}
    25  
    26  	// Retrieving operator key from environment variable OPERATOR_KEY
    27  	operatorKey, err := hedera.PrivateKeyFromString(os.Getenv("OPERATOR_KEY"))
    28  	if err != nil {
    29  		panic(fmt.Sprintf("%v : error converting string to PrivateKey", err))
    30  	}
    31  
    32  	// Setting the client operator ID and key
    33  	client.SetOperator(operatorAccountID, operatorKey)
    34  
    35  	accountID, _ := hedera.AccountIDFromString("0.0.1999")
    36  	description := "Hedera™ cryptocurrency"
    37  	newDescription := "Hedera™ cryptocurrency - updated"
    38  
    39  	ipv4 := []byte{127, 0, 0, 1}
    40  
    41  	gossipEndpoint := hedera.Endpoint{}
    42  	gossipEndpoint.SetAddress(ipv4).SetPort(50211)
    43  
    44  	serviceEndpoint := hedera.Endpoint{}
    45  	serviceEndpoint.SetAddress(ipv4).SetPort(50211)
    46  
    47  	adminKey, _ := hedera.PrivateKeyGenerateEd25519()
    48  
    49  	nodeCreateTransaction := hedera.NewNodeCreateTransaction().
    50  		SetAccountID(accountID).
    51  		SetDescription(description).
    52  		SetGossipCaCertificate([]byte("gossipCaCertificate")).
    53  		SetServiceEndpoints([]hedera.Endpoint{serviceEndpoint}).
    54  		SetGossipEndpoints([]hedera.Endpoint{gossipEndpoint}).
    55  		SetAdminKey(adminKey.PublicKey())
    56  
    57  	resp, err := nodeCreateTransaction.Execute(client)
    58  	fmt.Println(err)
    59  	_, err = resp.SetValidateStatus(true).GetReceipt(client)
    60  	fmt.Println(err)
    61  
    62  	nodeUpdateTransaction := hedera.NewNodeUpdateTransaction().
    63  		SetNodeID(123).
    64  		SetDescription(newDescription).
    65  		SetGossipCaCertificate([]byte("gossipCaCertificate")).
    66  		SetServiceEndpoints([]hedera.Endpoint{serviceEndpoint}).
    67  		SetGossipEndpoints([]hedera.Endpoint{gossipEndpoint}).
    68  		SetAdminKey(adminKey.PublicKey())
    69  	resp, err = nodeUpdateTransaction.Execute(client)
    70  	fmt.Println(err)
    71  
    72  	_, err = resp.SetValidateStatus(true).GetReceipt(client)
    73  	fmt.Println(err)
    74  
    75  	nodeDeleteTransaction := hedera.NewNodeDeleteTransaction().
    76  		SetNodeID(123)
    77  	resp, err = nodeDeleteTransaction.Execute(client)
    78  	fmt.Println(err)
    79  
    80  	_, err = resp.SetValidateStatus(true).GetReceipt(client)
    81  	fmt.Println(err)
    82  }