9
9
from hiero_sdk_python .tokens .token_create_transaction import TokenCreateTransaction
10
10
from hiero_sdk_python .tokens .token_associate_transaction import TokenAssociateTransaction
11
11
from hiero_sdk_python .tokens .token_dissociate_transaction import TokenDissociateTransaction
12
+ from hiero_sdk_python .tokens .token_mint_transaction import TokenMintTransaction
12
13
from hiero_sdk_python .transaction .transfer_transaction import TransferTransaction
13
14
from hiero_sdk_python .tokens .token_delete_transaction import TokenDeleteTransaction
14
15
from hiero_sdk_python .response_code import ResponseCode
20
21
from hiero_sdk_python .query .topic_info_query import TopicInfoQuery
21
22
from hiero_sdk_python .query .account_balance_query import CryptoGetAccountBalanceQuery
22
23
23
-
24
24
load_dotenv ()
25
25
26
26
@@ -68,15 +68,15 @@ def query_balance(client, account_id):
68
68
print (f"Account { account_id } balance: { balance .hbars } " )
69
69
return balance
70
70
71
-
72
- def create_token (client , operator_id , admin_key ):
71
+ def create_token (client , operator_id , admin_key , supply_key ):
73
72
transaction = TokenCreateTransaction (
74
73
token_name = "ExampleToken" ,
75
74
token_symbol = "EXT" ,
76
75
decimals = 2 ,
77
76
initial_supply = 1000 ,
78
77
treasury_account_id = operator_id ,
79
- admin_key = admin_key
78
+ admin_key = admin_key ,
79
+ supply_key = supply_key
80
80
)
81
81
transaction .freeze_with (client )
82
82
transaction .sign (client .operator_private_key )
@@ -172,6 +172,70 @@ def delete_token(client, token_id, admin_key):
172
172
sys .exit (1 )
173
173
174
174
175
+ def mint_fungible_token (client , token_id , supply_key , amount = 2000 ):
176
+ transaction = TokenMintTransaction (token_id = token_id , amount = amount )
177
+ transaction .freeze_with (client )
178
+ transaction .sign (client .operator_private_key )
179
+ transaction .sign (supply_key )
180
+
181
+ try :
182
+ receipt = transaction .execute (client )
183
+ if receipt .status != ResponseCode .SUCCESS :
184
+ status_message = ResponseCode .get_name (receipt .status )
185
+ raise Exception (f"Token minting failed with status: { status_message } " )
186
+ print ("Token minting successful." )
187
+ except Exception as e :
188
+ print (f"Token minting failed: { str (e )} " )
189
+ sys .exit (1 )
190
+
191
+ def mint_nft_token (client , token_id , supply_key , metadata = [b"Token A" ]):
192
+ transaction = TokenMintTransaction (token_id = token_id , metadata = metadata )
193
+ transaction .freeze_with (client )
194
+ transaction .sign (client .operator_private_key )
195
+ transaction .sign (supply_key )
196
+
197
+ try :
198
+ receipt = transaction .execute (client )
199
+ if receipt .status != ResponseCode .SUCCESS :
200
+ status_message = ResponseCode .get_name (receipt .status )
201
+ raise Exception (f"Token minting failed with status: { status_message } " )
202
+ print ("Token minting successful." )
203
+ except Exception as e :
204
+ print (f"Token minting failed: { str (e )} " )
205
+ sys .exit (1 )
206
+
207
+ def mint_fungible_token (client , token_id , supply_key , amount = 2000 ):
208
+ transaction = TokenMintTransaction (token_id = token_id , amount = amount )
209
+ transaction .freeze_with (client )
210
+ transaction .sign (client .operator_private_key )
211
+ transaction .sign (supply_key )
212
+
213
+ try :
214
+ receipt = transaction .execute (client )
215
+ if receipt .status != ResponseCode .SUCCESS :
216
+ status_message = ResponseCode .get_name (receipt .status )
217
+ raise Exception (f"Token minting failed with status: { status_message } " )
218
+ print ("Token minting successful." )
219
+ except Exception as e :
220
+ print (f"Token minting failed: { str (e )} " )
221
+ sys .exit (1 )
222
+
223
+ def mint_nft_token (client , token_id , supply_key , metadata = [b"Token A" ]):
224
+ transaction = TokenMintTransaction (token_id = token_id , metadata = metadata )
225
+ transaction .freeze_with (client )
226
+ transaction .sign (client .operator_private_key )
227
+ transaction .sign (supply_key )
228
+
229
+ try :
230
+ receipt = transaction .execute (client )
231
+ if receipt .status != ResponseCode .SUCCESS :
232
+ status_message = ResponseCode .get_name (receipt .status )
233
+ raise Exception (f"Token minting failed with status: { status_message } " )
234
+ print ("Token minting successful." )
235
+ except Exception as e :
236
+ print (f"Token minting failed: { str (e )} " )
237
+ sys .exit (1 )
238
+
175
239
def create_topic (client ):
176
240
key = client .operator_private_key
177
241
transaction = TopicCreateTransaction (
@@ -270,6 +334,7 @@ def query_topic_info(client, topic_id):
270
334
def main ():
271
335
operator_id , operator_key = load_operator_credentials ()
272
336
admin_key = PrivateKey .generate ()
337
+ supply_key = PrivateKey .generate ()
273
338
274
339
network_type = os .getenv ('NETWORK' )
275
340
network = Network (network = network_type )
@@ -279,8 +344,11 @@ def main():
279
344
recipient_id , recipient_private_key = create_new_account (client )
280
345
query_balance (client , recipient_id )
281
346
282
- token_id_1 = create_token (client , operator_id , admin_key )
283
- token_id_2 = create_token (client , operator_id , admin_key )
347
+ token_id_1 = create_token (client , operator_id , admin_key , supply_key )
348
+ token_id_2 = create_token (client , operator_id , admin_key , supply_key )
349
+
350
+ mint_fungible_token (client , token_id_1 , supply_key )
351
+ mint_nft_token (client , token_id_1 , supply_key )
284
352
285
353
associate_token (client , recipient_id , recipient_private_key , [token_id_1 , token_id_2 ])
286
354
transfer_token (client , operator_id , operator_key , recipient_id , token_id_1 )
0 commit comments