33import Foundation
44import Hiero
55import HieroExampleUtilities
6- import SwiftDotenv
76
87@main
98internal enum Program {
109 internal static func main( ) async throws {
11-
12- let env = try Dotenv . load ( )
10+ let env = try Environment . load ( )
1311 let client = try Client . forName ( env. networkName)
1412
1513 client. setOperator ( env. operatorAccountId, env. operatorKey)
@@ -50,14 +48,16 @@ internal enum Program {
5048
5149 // now pretend we sent those bytes across the network
5250 // parse them into a transaction so we can sign as the submit key
53- let deserializedTransaction = try Transaction . fromBytes ( transactionBytes) as! TopicMessageSubmitTransaction
54-
51+ let deserializedTransaction = try Transaction . fromBytes ( transactionBytes)
52+ guard let topicMessageSubmitTransaction = deserializedTransaction as? TopicMessageSubmitTransaction else {
53+ fatalError ( " Expected TopicMessageSubmitTransaction " )
54+ }
5555 // sign with that submit key
56- deserializedTransaction . sign ( submitKey)
56+ topicMessageSubmitTransaction . sign ( submitKey)
5757
5858 // now actually submit the transaction
5959 // get the receipt to ensure there were no errors
60- _ = try await deserializedTransaction . execute ( client) . getReceipt ( client)
60+ _ = try await topicMessageSubmitTransaction . execute ( client) . getReceipt ( client)
6161
6262 print ( " Finished sending the message, press ctrl+c to exit once it's recieved " )
6363 }
@@ -74,22 +74,3 @@ internal enum Program {
7474 }
7575 }
7676}
77-
78- extension Environment {
79- /// Account ID for the operator to use in this example.
80- internal var operatorAccountId : AccountId {
81- AccountId ( self [ " OPERATOR_ID " ] !. stringValue) !
82- }
83-
84- /// Private key for the operator to use in this example.
85- internal var operatorKey : PrivateKey {
86- PrivateKey ( self [ " OPERATOR_KEY " ] !. stringValue) !
87- }
88-
89- /// The name of the hedera network this example should be ran against.
90- ///
91- /// Testnet by default.
92- internal var networkName : String {
93- self [ " HEDERA_NETWORK " ] ? . stringValue ?? " testnet "
94- }
95- }
0 commit comments