Skip to content

Commit 5d440e2

Browse files
committed
adding TokenMintTransaction back into test file
Signed-off-by: nadine.loepfe <[email protected]>
1 parent 6ddc91d commit 5d440e2

File tree

1 file changed

+74
-6
lines changed

1 file changed

+74
-6
lines changed

test.py

Lines changed: 74 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from hiero_sdk_python.tokens.token_create_transaction import TokenCreateTransaction
1010
from hiero_sdk_python.tokens.token_associate_transaction import TokenAssociateTransaction
1111
from hiero_sdk_python.tokens.token_dissociate_transaction import TokenDissociateTransaction
12+
from hiero_sdk_python.tokens.token_mint_transaction import TokenMintTransaction
1213
from hiero_sdk_python.transaction.transfer_transaction import TransferTransaction
1314
from hiero_sdk_python.tokens.token_delete_transaction import TokenDeleteTransaction
1415
from hiero_sdk_python.response_code import ResponseCode
@@ -20,7 +21,6 @@
2021
from hiero_sdk_python.query.topic_info_query import TopicInfoQuery
2122
from hiero_sdk_python.query.account_balance_query import CryptoGetAccountBalanceQuery
2223

23-
2424
load_dotenv()
2525

2626

@@ -68,15 +68,15 @@ def query_balance(client, account_id):
6868
print(f"Account {account_id} balance: {balance.hbars}")
6969
return balance
7070

71-
72-
def create_token(client, operator_id, admin_key):
71+
def create_token(client, operator_id, admin_key, supply_key):
7372
transaction = TokenCreateTransaction(
7473
token_name="ExampleToken",
7574
token_symbol="EXT",
7675
decimals=2,
7776
initial_supply=1000,
7877
treasury_account_id=operator_id,
79-
admin_key=admin_key
78+
admin_key=admin_key,
79+
supply_key=supply_key
8080
)
8181
transaction.freeze_with(client)
8282
transaction.sign(client.operator_private_key)
@@ -172,6 +172,70 @@ def delete_token(client, token_id, admin_key):
172172
sys.exit(1)
173173

174174

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+
175239
def create_topic(client):
176240
key = client.operator_private_key
177241
transaction = TopicCreateTransaction(
@@ -270,6 +334,7 @@ def query_topic_info(client, topic_id):
270334
def main():
271335
operator_id, operator_key = load_operator_credentials()
272336
admin_key = PrivateKey.generate()
337+
supply_key = PrivateKey.generate()
273338

274339
network_type = os.getenv('NETWORK')
275340
network = Network(network=network_type)
@@ -279,8 +344,11 @@ def main():
279344
recipient_id, recipient_private_key = create_new_account(client)
280345
query_balance(client, recipient_id)
281346

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)
284352

285353
associate_token(client, recipient_id, recipient_private_key, [token_id_1, token_id_2])
286354
transfer_token(client, operator_id, operator_key, recipient_id, token_id_1)

0 commit comments

Comments
 (0)