Skip to content

Commit

Permalink
adding TokenMintTransaction back into test file
Browse files Browse the repository at this point in the history
Signed-off-by: nadine.loepfe <[email protected]>
  • Loading branch information
nadineloepfe committed Jan 31, 2025
1 parent 6ddc91d commit 5d440e2
Showing 1 changed file with 74 additions and 6 deletions.
80 changes: 74 additions & 6 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from hiero_sdk_python.tokens.token_create_transaction import TokenCreateTransaction
from hiero_sdk_python.tokens.token_associate_transaction import TokenAssociateTransaction
from hiero_sdk_python.tokens.token_dissociate_transaction import TokenDissociateTransaction
from hiero_sdk_python.tokens.token_mint_transaction import TokenMintTransaction
from hiero_sdk_python.transaction.transfer_transaction import TransferTransaction
from hiero_sdk_python.tokens.token_delete_transaction import TokenDeleteTransaction
from hiero_sdk_python.response_code import ResponseCode
Expand All @@ -20,7 +21,6 @@
from hiero_sdk_python.query.topic_info_query import TopicInfoQuery
from hiero_sdk_python.query.account_balance_query import CryptoGetAccountBalanceQuery


load_dotenv()


Expand Down Expand Up @@ -68,15 +68,15 @@ def query_balance(client, account_id):
print(f"Account {account_id} balance: {balance.hbars}")
return balance


def create_token(client, operator_id, admin_key):
def create_token(client, operator_id, admin_key, supply_key):
transaction = TokenCreateTransaction(
token_name="ExampleToken",
token_symbol="EXT",
decimals=2,
initial_supply=1000,
treasury_account_id=operator_id,
admin_key=admin_key
admin_key=admin_key,
supply_key=supply_key
)
transaction.freeze_with(client)
transaction.sign(client.operator_private_key)
Expand Down Expand Up @@ -172,6 +172,70 @@ def delete_token(client, token_id, admin_key):
sys.exit(1)


def mint_fungible_token(client, token_id, supply_key, amount=2000):
transaction = TokenMintTransaction(token_id=token_id, amount=amount)
transaction.freeze_with(client)
transaction.sign(client.operator_private_key)
transaction.sign(supply_key)

try:
receipt = transaction.execute(client)
if receipt.status != ResponseCode.SUCCESS:
status_message = ResponseCode.get_name(receipt.status)
raise Exception(f"Token minting failed with status: {status_message}")
print("Token minting successful.")
except Exception as e:
print(f"Token minting failed: {str(e)}")
sys.exit(1)

def mint_nft_token(client, token_id, supply_key, metadata=[b"Token A"]):
transaction = TokenMintTransaction(token_id=token_id, metadata=metadata )
transaction.freeze_with(client)
transaction.sign(client.operator_private_key)
transaction.sign(supply_key)

try:
receipt = transaction.execute(client)
if receipt.status != ResponseCode.SUCCESS:
status_message = ResponseCode.get_name(receipt.status)
raise Exception(f"Token minting failed with status: {status_message}")
print("Token minting successful.")
except Exception as e:
print(f"Token minting failed: {str(e)}")
sys.exit(1)

def mint_fungible_token(client, token_id, supply_key, amount=2000):
transaction = TokenMintTransaction(token_id=token_id, amount=amount)
transaction.freeze_with(client)
transaction.sign(client.operator_private_key)
transaction.sign(supply_key)

try:
receipt = transaction.execute(client)
if receipt.status != ResponseCode.SUCCESS:
status_message = ResponseCode.get_name(receipt.status)
raise Exception(f"Token minting failed with status: {status_message}")
print("Token minting successful.")
except Exception as e:
print(f"Token minting failed: {str(e)}")
sys.exit(1)

def mint_nft_token(client, token_id, supply_key, metadata=[b"Token A"]):
transaction = TokenMintTransaction(token_id=token_id, metadata=metadata )
transaction.freeze_with(client)
transaction.sign(client.operator_private_key)
transaction.sign(supply_key)

try:
receipt = transaction.execute(client)
if receipt.status != ResponseCode.SUCCESS:
status_message = ResponseCode.get_name(receipt.status)
raise Exception(f"Token minting failed with status: {status_message}")
print("Token minting successful.")
except Exception as e:
print(f"Token minting failed: {str(e)}")
sys.exit(1)

def create_topic(client):
key = client.operator_private_key
transaction = TopicCreateTransaction(
Expand Down Expand Up @@ -270,6 +334,7 @@ def query_topic_info(client, topic_id):
def main():
operator_id, operator_key = load_operator_credentials()
admin_key = PrivateKey.generate()
supply_key = PrivateKey.generate()

network_type = os.getenv('NETWORK')
network = Network(network=network_type)
Expand All @@ -279,8 +344,11 @@ def main():
recipient_id, recipient_private_key = create_new_account(client)
query_balance(client, recipient_id)

token_id_1 = create_token(client, operator_id, admin_key)
token_id_2 = create_token(client, operator_id, admin_key)
token_id_1 = create_token(client, operator_id, admin_key, supply_key)
token_id_2 = create_token(client, operator_id, admin_key, supply_key)

mint_fungible_token(client, token_id_1, supply_key)
mint_nft_token(client, token_id_1, supply_key)

associate_token(client, recipient_id, recipient_private_key, [token_id_1, token_id_2])
transfer_token(client, operator_id, operator_key, recipient_id, token_id_1)
Expand Down

0 comments on commit 5d440e2

Please sign in to comment.