github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/examples/rng_transaction/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 createResponse, err := hedera.NewPrngTransaction(). 36 // Set the range 37 SetRange(12). 38 Execute(client) 39 if err != nil { 40 panic(fmt.Sprintf("%v : error executing rng transaction", err)) 41 } 42 43 transactionRecord, err := createResponse.GetRecord(client) 44 if err != nil { 45 panic(fmt.Sprintf("%v : error getting receipt", err)) 46 } 47 fmt.Printf("transactionRecord: %v\n", transactionRecord) 48 if transactionRecord.PrngNumber == nil { 49 panic(fmt.Sprintf("%v : error, pseudo-random number is nil", err)) 50 } 51 52 println("The pseudo-random number is:", *transactionRecord.PrngNumber) 53 }