@@ -57,7 +57,7 @@ def create_account(client, operator_key):
5757
5858def create_token (client , operator_id , operator_key ):
5959 """Create a fungible token"""
60- print ("\n Creating a token..." )
60+ print ("\n Step 1: Creating a fungible token (TKA) ..." )
6161 try :
6262 token_tx = (
6363 TokenCreateTransaction ()
@@ -79,7 +79,7 @@ def create_token(client, operator_id, operator_key):
7979
8080def create_nft (client , operator_key , operator_id ):
8181 """Create a NFT"""
82- print ("\n Creating a nft ..." )
82+ print ("\n Step 2: Creating a non-fungible token (NFTA) ..." )
8383 try :
8484 nft_tx = (
8585 TokenCreateTransaction ()
@@ -101,7 +101,7 @@ def create_nft(client, operator_key, operator_id):
101101
102102def mint_nft (client , operator_key , nft_id ):
103103 """Mint the NFT with metadata"""
104- print ("\n Minting a nft ..." )
104+ print ("\n Step 3: Minting an NFT for NFTA ..." )
105105 try :
106106 mint_tx = TokenMintTransaction (token_id = nft_id , metadata = [b"NFT data" ])
107107 mint_tx .freeze_with (client )
@@ -117,7 +117,7 @@ def mint_nft(client, operator_key, nft_id):
117117
118118def associate_tokens (client , recipient_id , recipient_key , tokens ):
119119 """Associate the token and nft with the recipient"""
120- print ("\n Associating tokens to recipient..." )
120+ print ("\n Step 4: Associating tokens to recipient..." )
121121 try :
122122 assocciate_tx = TokenAssociateTransaction (
123123 account_id = recipient_id ,
@@ -132,10 +132,9 @@ def associate_tokens(client, recipient_id, recipient_key, tokens):
132132 .execute (client )
133133 .token_balances
134134 )
135- print ("Tokens associated with recipient:" )
136- print (f"{ tokens [0 ]} : { balance_before .get (tokens [0 ])} " )
137- print (f"{ tokens [1 ]} : { balance_before .get (tokens [1 ])} " )
138-
135+ print ("Tokens associated with recipient (should be 0 for both):" )
136+ print (f" { tokens [0 ]} : { balance_before .get (tokens [0 ], 0 )} " )
137+ print (f" { tokens [1 ]} : { balance_before .get (tokens [1 ], 0 )} " )
139138 print ("\n ✅ Success! Token association complete." )
140139
141140 except Exception as e :
@@ -160,14 +159,25 @@ def token_airdrop():
160159 # Create a nft
161160 nft_id = create_nft (client , operator_key , operator_id )
162161
163- #Mint nft
162+ # Mint nft
164163 serial_number = mint_nft (client , operator_key , nft_id )
165164
166165 # Associate tokens
167166 associate_tokens (client , recipient_id , recipient_key , [token_id , nft_id ])
168167
169- # Airdrop Tthe tokens
170- print ("\n Airdropping tokens..." )
168+ # Log balances before airdrop
169+ print ("\n Step 5: Checking balances before airdrop..." )
170+ sender_balances_before = CryptoGetAccountBalanceQuery (account_id = operator_id ).execute (client ).token_balances
171+ recipient_balances_before = CryptoGetAccountBalanceQuery (account_id = recipient_id ).execute (client ).token_balances
172+ print (f"Sender ({ operator_id } ) balances before airdrop:" )
173+ print (f" { token_id } : { sender_balances_before .get (token_id , 0 )} " )
174+ print (f" { nft_id } : { sender_balances_before .get (nft_id , 0 )} " )
175+ print (f"Recipient ({ recipient_id } ) balances before airdrop:" )
176+ print (f" { token_id } : { recipient_balances_before .get (token_id , 0 )} " )
177+ print (f" { nft_id } : { recipient_balances_before .get (nft_id , 0 )} " )
178+
179+ # Airdrop the tokens
180+ print (f"\n Step 6: Airdropping fungible token TKA ({ token_id } ) and NFTA ({ nft_id } , serial { serial_number } ) to recipient { recipient_id } ..." )
171181 try :
172182 airdrop_receipt = (
173183 TokenAirdropTransaction ()
@@ -183,24 +193,35 @@ def token_airdrop():
183193 )
184194
185195 if airdrop_receipt .status != ResponseCode .SUCCESS :
186- print (f"Fail to cancel airdrop: Status: { airdrop_receipt .status } " )
196+ print (f"❌ Fail to airdrop: Status: { airdrop_receipt .status } " )
187197 sys .exit (1 )
188198
189199 print (f"Token airdrop ID: { airdrop_receipt .transaction_id } " )
190200
191- after_balance = (
192- CryptoGetAccountBalanceQuery (account_id = recipient_id )
193- .execute (client )
194- .token_balances
195- )
196- print ("Recipient balance after token airdrop:" )
197- print (f"{ token_id } : { after_balance .get (token_id )} " )
198- print (f"{ nft_id } : { after_balance .get (nft_id )} " )
199-
201+ # Log balances after airdrop
202+ sender_balances_after = CryptoGetAccountBalanceQuery (account_id = operator_id ).execute (client ).token_balances
203+ recipient_balances_after = CryptoGetAccountBalanceQuery (account_id = recipient_id ).execute (client ).token_balances
204+ print ("\n Balances after airdrop:" )
205+ print (f"Sender ({ operator_id } ):" )
206+ print (f" { str (token_id )} : { sender_balances_after .get (str (token_id ), 0 )} " )
207+ print (f" { str (nft_id )} : { sender_balances_after .get (str (nft_id ), 0 )} " )
208+ print (f"Recipient ({ recipient_id } ):" )
209+ print (f" { str (token_id )} : { recipient_balances_after .get (str (token_id ), 0 )} " )
210+ print (f" { str (nft_id )} : { recipient_balances_after .get (str (nft_id ), 0 )} " )
211+
212+ # Summary table
213+ print ("\n Summary Table:" )
214+ print ("+----------------+----------------------+----------------------+----------------------+----------------------+" )
215+ print ("| Token Type | Token ID | NFT Serial | Sender Balance | Recipient Balance |" )
216+ print ("+----------------+----------------------+----------------------+----------------------+----------------------+" )
217+ print (f"| Fungible (TKA) | { str (token_id ):20} | -{ '' :20} | { str (sender_balances_after .get (str (token_id ), 0 )):20} | { str (recipient_balances_after .get (str (token_id ), 0 )):20} |" )
218+ print (f"| NFT (NFTA) | { str (nft_id ):20} | { str (serial_number ):20} | { str (sender_balances_after .get (str (nft_id ), 0 )):20} | { str (recipient_balances_after .get (str (nft_id ), 0 )):20} |" )
219+ print ("+----------------+----------------------+----------------------+----------------------+----------------------+" )
200220 print ("\n ✅ Success! Token Airdrop transaction successful" )
201221 except Exception as e :
202222 print (f"❌ Error airdropping tokens: { e } " )
203223 sys .exit (1 )
204224
205225if __name__ == "__main__" :
206226 token_airdrop ()
227+
0 commit comments