github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/examples/get_file_contents/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 // Constructors exist for convenient files 36 //fileID := hedera.FileIDForAddressBook() 37 // fileID := hedera.FileIDForFeeSchedule() 38 fileID := hedera.FileIDForExchangeRate() 39 40 contents, err := hedera.NewFileContentsQuery(). 41 // Set the file ID for whatever file you need 42 SetFileID(fileID). 43 Execute(client) 44 45 if err != nil { 46 panic(fmt.Sprintf("%v : error executing file contents query", err)) 47 } 48 49 exchangeRate, err := hedera.ExchangeRateFromBytes(contents) 50 if err != nil { 51 panic(fmt.Sprintf("%v : error converting contents to exchange rate", err)) 52 } 53 54 fmt.Printf("Contents for file %v :\n", fileID.String()) 55 fmt.Print(exchangeRate.String()) 56 fmt.Println() 57 }