8
8
from hedera_sdk_python .crypto .private_key import PrivateKey
9
9
from hedera_sdk_python .tokens .token_create_transaction import TokenCreateTransaction
10
10
from hedera_sdk_python .tokens .token_associate_transaction import TokenAssociateTransaction
11
- from hedera_sdk_python .tokens .token_dissociate_transaction import TokenDissociateTransaction
12
11
from hedera_sdk_python .transaction .transfer_transaction import TransferTransaction
13
12
from hedera_sdk_python .tokens .token_delete_transaction import TokenDeleteTransaction
14
13
from hedera_sdk_python .response_code import ResponseCode
19
18
from hedera_sdk_python .consensus .topic_id import TopicId
20
19
from hedera_sdk_python .query .topic_info_query import TopicInfoQuery
21
20
from hedera_sdk_python .query .account_balance_query import CryptoGetAccountBalanceQuery
21
+
22
22
load_dotenv ()
23
23
24
24
def load_operator_credentials ():
@@ -90,10 +90,10 @@ def create_token(client, operator_id, admin_key):
90
90
print (f"Token creation successful. Token ID: { token_id } " )
91
91
return token_id
92
92
93
- def associate_token (client , recipient_id , recipient_private_key , token_ids ):
93
+ def associate_token (client , recipient_id , recipient_private_key , token_id ):
94
94
transaction = TokenAssociateTransaction (
95
95
account_id = recipient_id ,
96
- token_ids = token_ids
96
+ token_ids = [ token_id ]
97
97
)
98
98
transaction .freeze_with (client )
99
99
transaction .sign (client .operator_private_key )
@@ -109,34 +109,16 @@ def associate_token(client, recipient_id, recipient_private_key, token_ids):
109
109
print (f"Token association failed: { str (e )} " )
110
110
sys .exit (1 )
111
111
112
- def dissociate_token (client , recipient_id , recipient_private_key , token_id ):
113
- """Dissociate the specified token with the recipient account."""
114
- transaction = TokenDissociateTransaction (
115
- account_id = recipient_id ,
116
- token_ids = token_id )
117
- transaction .freeze_with (client )
118
- transaction .sign (client .operator_private_key )
119
- transaction .sign (recipient_private_key )
120
-
121
- try :
122
- receipt = transaction .execute (client )
123
- if receipt .status != ResponseCode .SUCCESS :
124
- status_message = ResponseCode .get_name (receipt .status )
125
- raise Exception (f"Token dissociation failed with status: { status_message } " )
126
- print ("Token dissociation successful." )
127
- except Exception as e :
128
- print (f"Token dissociation failed: { str (e )} " )
129
- sys .exit (1 )
130
-
131
- def transfer_token (client , source_id , source_private_key , recipient_id , token_id ):
132
- """Transfer the specified token to the recipient account."""
133
- transaction = (
134
- TransferTransaction ()
135
- .add_token_transfer (token_id , source_id , - 1 )
136
- .add_token_transfer (token_id , recipient_id , 1 )
137
- .freeze_with (client )
138
- )
139
- transaction .sign (source_private_key )
112
+ def transfer_token (client , recipient_id , token_id ):
113
+ transaction = TransferTransaction (
114
+ token_transfers = {
115
+ token_id : {
116
+ client .operator_account_id : - 1 ,
117
+ recipient_id : 1 ,
118
+ }
119
+ }
120
+ ).freeze_with (client )
121
+ transaction .sign (client .operator_private_key )
140
122
141
123
try :
142
124
receipt = transaction .execute (client )
@@ -266,13 +248,10 @@ def main():
266
248
recipient_id , recipient_private_key = create_new_account (client )
267
249
query_balance (client , recipient_id )
268
250
269
- token_id_1 = create_token (client , operator_id , admin_key )
270
- token_id_2 = create_token (client , operator_id , admin_key )
271
-
272
- associate_token (client , recipient_id , recipient_private_key , [token_id_1 , token_id_2 ])
273
- transfer_token (client , operator_id , operator_key , recipient_id , token_id_1 )
274
- dissociate_token (client , recipient_id , recipient_private_key , [token_id_2 ])
275
- delete_token (client , token_id_1 , admin_key )
251
+ token_id = create_token (client , operator_id , admin_key )
252
+ associate_token (client , recipient_id , recipient_private_key , token_id )
253
+ transfer_token (client , recipient_id , token_id )
254
+ delete_token (client , token_id , admin_key )
276
255
277
256
topic_id = create_topic (client )
278
257
submit_message (client , topic_id )
0 commit comments