Hedera Token Service - Part 3: How to Pause, Freeze, Wipe, and Delete NFTs
In Part 1 of the series, you saw how to mint and transfer an NFT using the Hedera Token Service (HTS). In Part 2, you saw how to enable and disable token Know Your Customer (KYC), update token properties (if a token is mutable), and schedule transactions. In Part 3, you will learn how to use HTS capabilities that help you manage your tokens. Specifically, you will learn how to:
Pause a token (stops all operations for a token ID)
Freeze an account (stops all token operations only for a specific account)
Wipe a token (wipe a partial or entire token balance for a specific account)
Delete a token (the token will remain on the ledger)
Prerequisites
We recommend you complete the following introduction to get a basic understanding of Hedera transactions. This example does not build upon the previous examples.
Get a Hedera testnet account.
Set up your environment here.
✅ If you want the entire code used for this tutorial, skip to the Code Check section below.
Pause a Token
The pause transaction prevents a token from being involved in any kind of operation across all accounts. Specifying a <pauseKey> during the creation of a token is a requirement to be able to pause token operations. The code below shows you that this key must sign the pause transaction. Note that you can’t pause a token if it doesn’t have a pause key. Also keep in mind that if this key was not set during token creation, then a token update to add this key is not possible.
Pausing a token may be useful in cases where a third party requests that you, as the administrator of a token, stop all operations for that token while something like an audit is conducted. The pause transaction provides you with a way to comply with requests of that nature.
In our example below, we pause the token, test that by trying a token transfer and checking the token pauseStatus, and then we unpause the token to enable operations again.
nft-part3.js
// PAUSE ALL TOKEN OEPRATIONSlet tokenPauseTx =awaitnewTokenPauseTransaction().setTokenId(tokenId).freezeWith(client).sign(pauseKey);let tokenPauseSubmitTx =awaittokenPauseTx.execute(client);let tokenPauseRx =awaittokenPauseSubmitTx.getReceipt(client);console.log(`- Token pause: ${tokenPauseRx.status}`);console.log(`- See: https://hashscan.io/${network}/transaction/${tokenPauseSubmitTx.transactionId}`);// TEST THE TOKEN PAUSE BY TRYING AN NFT TRANSFER (TREASURY -> ALICE)let tokenTransferTx3 =awaitnewTransferTransaction().addNftTransfer(tokenId,3, treasuryId, aliceId).freezeWith(client).sign(treasuryKey);let tokenTransferSubmit3 =awaittokenTransferTx3.execute(client);try {let tokenTransferRx3 =awaittokenTransferSubmit3.getReceipt(client);console.log(`\n-NFT transfer Treasury -> Alice status: ${tokenTransferRx3.status}` );} catch {// TOKEN QUERY TO CHECK PAUSEvar tokenInfo =awaittQueryFcn();console.log(`\n- NFT transfer unsuccessful: Token ${tokenId} is paused (${tokenInfo.pauseStatus})` );console.log(`- See: https://hashscan.io/${network}/transaction/${tokenTransferSubmit3.transactionId}` );}// UNPAUSE ALL TOKEN OPERATIONSlet tokenUnpauseTx =awaitnewTokenUnpauseTransaction().setTokenId(tokenId).freezeWith(client).sign(pauseKey);let tokenUnpauseSubmitTx =awaittokenUnpauseTx.execute(client);let tokenUnpauseRx =awaittokenUnpauseSubmitTx.getReceipt(client);console.log(`- Token unpause: ${tokenUnpauseRx.status}\n`);console.log(`- See: https://hashscan.io/${network}/transaction/${tokenUnpauseSubmitTx.transactionId}`);
// TOKEN QUERY FUNCTION ==========================================asyncfunctiontQueryFcn() {var tokenInfo =awaitnewTokenInfoQuery().setTokenId(tokenId).execute(client);return tokenInfo; }
Freezing a token stops "freezes" transfers of that token for a specific account ID. Note that this transaction must be signed by the <freezeKey> of the token. Once a freeze executes, the specified account is marked as “Frozen” and will not be able to receive or send tokens unless unfrozen.
In our example below, we first freeze Alice’s account for the token ID we’re working with, test the freeze by trying a token transfer, and then unfreeze Alice’s account so she can transact the token again.
nft-part3.js
// FREEZE ALICE'S ACCOUNT FOR THIS TOKENlet tokenFreezeTx =awaitnewTokenFreezeTransaction().setTokenId(tokenId).setAccountId(aliceId).freezeWith(client).sign(freezeKey);let tokenFreezeSubmitTx =awaittokenFreezeTx.execute(client);let tokenFreezeRx =awaittokenFreezeSubmitTx.getReceipt(client);console.log(`\n- Freeze Alice's account for token ${tokenId}: ${tokenFreezeRx.status}`);console.log(`- See: https://hashscan.io/${network}/transaction/${tokenFreezeSubmitTx.transactionId}`);// TEST THE TOKEN FREEZE FOR THE ACCOUNT BY TRYING A TRANSFER (ALICE -> BOB)let tokenTransferTx4 =awaitnewTransferTransaction().addNftTransfer(tokenId,2, aliceId, bobId).addHbarTransfer(aliceId, nftPrice).addHbarTransfer(bobId,nftPrice.negated()).freezeWith(client).sign(aliceKey);let tokenTransferTx4Sign =awaittokenTransferTx4.sign(bobKey);let tokenTransferSubmit4 =awaittokenTransferTx4Sign.execute(client);try {let tokenTransferRx4 =awaittokenTransferSubmit4.getReceipt(client);console.log(`\n- NFT transfer Alice -> Bob status: ${tokenTransferRx4.status}` );} catch {console.log(`\n- NFT transfer Alice -> Bob unsuccessful: Alice's account is frozen for this token` );console.log(`- See: https://hashscan.io/${network}/transaction/${tokenTransferSubmit4.transactionId}` );}// UNFREEZE ALICE'S ACCOUNT FOR THIS TOKENlet tokenUnfreezeTx =awaitnewTokenUnfreezeTransaction().setTokenId(tokenId).setAccountId(aliceId).freezeWith(client).sign(freezeKey);let tokenUnfreezeSubmitTx =awaittokenUnfreezeTx.execute(client);let tokenUnfreezeRx =awaittokenUnfreezeSubmitTx.getReceipt(client);console.log(`\n- Unfreeze Alice's account for token ${tokenId}: ${tokenUnfreezeRx.status}`);console.log(`- See: https://hashscan.io/${network}/transaction/${tokenUnfreezeSubmitTx.transactionId}`);
Console output:
-FreezeAlice's account for token 0.0.46864: SUCCESS- See: https://hashscan.io/testnet/transaction/0.0.46446@1723772402.841848773- NFT transfer Alice -> Bob unsuccessful: Alice'saccountisfrozenforthistoken-See:https://hashscan.io/testnet/transaction/0.0.46446@1723772405.380352596-UnfreezeAlice's account for token 0.0.4686491: SUCCESS- See: https://hashscan.io/testnet/transaction/0.0.46446@1723772403.655969673
Wipe a Token
This operation wipes the provided amount of fungible or non-fungible tokens from the specified account. You see from the code below that this transaction must be signed by the token's <wipeKey>.
Note: Wiping an account's tokens burns the tokens and decreases the total supply. This transaction does not delete tokens from the treasury account. You must use the Token Burn operation to delete tokens from the treasury.
In this case, we wipe the NFT that Alice currently holds. We then check Alice’s balance and the NFT supply to see how these change with the wipe operation (these two values before the wipe are provided for comparison – see Part 2 for the details).
nft-part3.js
// WIPE THE TOKEN FROM ALICE'S ACCOUNTlet tokenWipeTx =awaitnewTokenWipeTransaction().setAccountId(aliceId).setTokenId(tokenId).setSerials([2]).freezeWith(client).sign(wipeKey);let tokenWipeSubmitTx =awaittokenWipeTx.execute(client);let tokenWipeRx =awaittokenWipeSubmitTx.getReceipt(client);console.log(`\n- Wipe token ${tokenId} from Alice's account: ${tokenWipeRx.status}`);console.log(`- See: https://hashscan.io/${network}/transaction/${tokenWipeSubmitTx.transactionId}`);// CHECK ALICE'S BALANCEaB =awaitbCheckerFcn(aliceId);console.log(`\n- Alice balance: ${aB[0]} NFTs of ID:${tokenId} and ${aB[1]}`);// TOKEN QUERY TO CHECK TOTAL TOKEN SUPPLYvar tokenInfo =awaittQueryFcn();console.log(`- Current NFT supply: ${tokenInfo.totalSupply}`);
Console output:
Delete a Token
After you delete a token, it’s no longer possible to perform any operations for that token, and transactions resolve to the error TOKEN_WAS_DELETED. Note that the token remains in the ledger, and you can still retrieve some information about it.
The delete operation must be signed by the token <adminKey>. Remember from Part 1 that if this key is not set during token creation, then the token is immutable and deletion is not possible.
In our example, we delete the token and perform a query to double-check that the deletion was successful. Note that for NFTs, you can’t delete a specific serial ID. Instead, you delete the entire class of the NFT specified by the token ID.
nft-part3.js
// DELETE THE TOKENlet tokenDeleteTx =awaitnewTokenDeleteTransaction().setTokenId(tokenId).freezeWith(client);let tokenDeleteSign =awaittokenDeleteTx.sign(adminKey);let tokenDeleteSubmit =awaittokenDeleteSign.execute(client);let tokenDeleteRx =awaittokenDeleteSubmit.getReceipt(client);console.log(`\n- Delete token ${tokenId}: ${tokenDeleteRx.status}`);console.log(`- See: https://hashscan.io/${network}/transaction/${tokenDeleteSubmitTx.transactionId}`);// TOKEN QUERY TO CHECK DELETIONvar tokenInfo =awaittQueryFcn();console.log(`- Token ${tokenId} is deleted: ${tokenInfo.isDeleted}`);
In this article, you saw key capabilities to help you manage your HTS tokens, including how to: pause, freeze, wipe, and delete tokens. If you haven’t already, check out Part 1 and Part 2 of this tutorial series to see examples of how to do even more with HTS – you will see how to mint NFTs, transfer NFTs, perform token KYC, schedule transactions, and more.
console.clear();require("dotenv").config();const {AccountId,PrivateKey,Client,TokenCreateTransaction,TokenInfoQuery,TokenType,CustomRoyaltyFee,CustomFixedFee,Hbar,HbarUnit,TokenSupplyType,TokenMintTransaction,TokenBurnTransaction,TransferTransaction,AccountBalanceQuery,AccountUpdateTransaction,TokenAssociateTransaction,TokenUpdateTransaction,TokenGrantKycTransaction,TokenRevokeKycTransaction,ScheduleCreateTransaction,ScheduleSignTransaction,ScheduleInfoQuery,TokenPauseTransaction,TokenUnpauseTransaction,TokenWipeTransaction,TokenFreezeTransaction,TokenUnfreezeTransaction,TokenDeleteTransaction,AccountCreateTransaction,} =require("@hashgraph/sdk");// CONFIGURE ACCOUNTS AND CLIENT, AND GENERATE accounts and client, and generate needed keysconstoperatorId=AccountId.fromString(process.env.OPERATOR_ID);constoperatorKey=PrivateKey.fromStringECDSA(process.env.OPERATOR_KEY_HEX);constnetwork=process.env.NETWORK;constclient=Client.forNetwork(network).setOperator(operatorId, operatorKey);client.setDefaultMaxTransactionFee(newHbar(50));client.setDefaultMaxQueryPayment(newHbar(1));asyncfunctionmain() {// CREATE NEW HEDERA ACCOUNTS TO REPRESENT OTHER USERSconstinitBalance=newHbar(1);consttreasuryKey=PrivateKey.generateECDSA();const [treasurySt,treasuryId] =awaitaccountCreateFcn(treasuryKey, initBalance, client);console.log(`- Treasury's account: https://hashscan.io/testnet/account/${treasuryId}`);constaliceKey=PrivateKey.generateECDSA();const [aliceSt,aliceId] =awaitaccountCreateFcn(aliceKey, initBalance, client);console.log(`- Alice's account: https://hashscan.io/testnet/account/${aliceId}`);constbobKey=PrivateKey.generateECDSA();const [bobSt,bobId] =awaitaccountCreateFcn(bobKey, initBalance, client);console.log(`- Bob's account: https://hashscan.io/testnet/account/${bobId}`);// GENERATE KEYS TO MANAGE FUNCTIONAL ASPECTS OF THE TOKENconstsupplyKey=PrivateKey.generateECDSA();constadminKey=PrivateKey.generateECDSA();constpauseKey=PrivateKey.generateECDSA();constfreezeKey=PrivateKey.generateECDSA();constwipeKey=PrivateKey.generateECDSA();constkycKey=PrivateKey.generate();constnewKycKey=PrivateKey.generate();// DEFINE CUSTOM FEE SCHEDULElet nftCustomFee =newCustomRoyaltyFee().setNumerator(1).setDenominator(10).setFeeCollectorAccountId(treasuryId).setFallbackFee(newCustomFixedFee().setHbarAmount(newHbar(1,HbarUnit.Tinybar))); // 1 HBAR = 100,000,000 Tinybar// IPFS CONTENT IDENTIFIERS FOR WHICH WE WILL CREATE NFTs - SEE uploadJsonToIpfs.jslet CIDs = [Buffer.from("ipfs://bafkreibr7cyxmy4iyckmlyzige4ywccyygomwrcn4ldcldacw3nxe3ikgq"),Buffer.from("ipfs://bafkreig73xgqp7wy7qvjwz33rp3nkxaxqlsb7v3id24poe2dath7pj5dhe"),Buffer.from("ipfs://bafkreigltq4oaoifxll3o2cc3e3q3ofqzu6puennmambpulxexo5sryc6e"),Buffer.from("ipfs://bafkreiaoswszev3uoukkepctzpnzw56ey6w3xscokvsvmfrqdzmyhas6fu"),Buffer.from("ipfs://bafkreih6cajqynaqwbrmiabk2jxpy56rpf25zvg5lbien73p5ysnpehyjm"), ];// CREATE NFT WITH CUSTOM FEElet nftCreateTx =awaitnewTokenCreateTransaction().setTokenName("Fall Collection").setTokenSymbol("LEAF").setTokenType(TokenType.NonFungibleUnique).setDecimals(0).setInitialSupply(0).setTreasuryAccountId(treasuryId).setSupplyType(TokenSupplyType.Finite).setMaxSupply(CIDs.length).setCustomFees([nftCustomFee]).setAdminKey(adminKey.publicKey).setSupplyKey(supplyKey.publicKey).setKycKey(kycKey.publicKey).setPauseKey(pauseKey.publicKey).setFreezeKey(freezeKey.publicKey).setWipeKey(wipeKey.publicKey).freezeWith(client).sign(treasuryKey);let nftCreateTxSign =awaitnftCreateTx.sign(adminKey);let nftCreateSubmit =awaitnftCreateTxSign.execute(client);let nftCreateRx =awaitnftCreateSubmit.getReceipt(client);let tokenId =nftCreateRx.tokenId;console.log(`\n- Created NFT with Token ID: ${tokenId}`);console.log(`- See: https://hashscan.io/${network}/transaction/${nftCreateSubmit.transactionId}`);// TOKEN QUERY TO CHECK THAT THE CUSTOM FEE SCHEDULE IS ASSOCIATED WITH NFTvar tokenInfo =awaittQueryFcn();console.log(` `);console.table(tokenInfo.customFees[0]);// MINT NEW BATCH OF NFTs - CAN MINT UP TO 10 NFT SERIALS IN A SINGLE TRANSACTIONlet [nftMintRx, mintTxId] =awaittokenMinterFcn(CIDs);console.log(`\n- Mint ${CIDs.length} serials for NFT collection ${tokenId}: ${nftMintRx.status}`);console.log(`- See: https://hashscan.io/${network}/transaction/${mintTxId}`);// BURN THE LAST NFT IN THE COLLECTIONlet tokenBurnTx =awaitnewTokenBurnTransaction().setTokenId(tokenId).setSerials([CIDs.length]).freezeWith(client).sign(supplyKey);let tokenBurnSubmit =awaittokenBurnTx.execute(client);let tokenBurnRx =awaittokenBurnSubmit.getReceipt(client);console.log(`\n- Burn NFT with serial ${CIDs.length}: ${tokenBurnRx.status}`);console.log(`- See: https://hashscan.io/${network}/transaction/${tokenBurnSubmit.transactionId}`);var tokenInfo =awaittQueryFcn();console.log(`- Current NFT supply: ${tokenInfo.totalSupply}`);// MANUAL ASSOCIATION FOR ALICE'S ACCOUNTlet associateAliceTx =awaitnewTokenAssociateTransaction().setAccountId(aliceId).setTokenIds([tokenId]).freezeWith(client).sign(aliceKey);let associateAliceTxSubmit =awaitassociateAliceTx.execute(client);let associateAliceRx =awaitassociateAliceTxSubmit.getReceipt(client);console.log(`\n- Alice NFT manual association: ${associateAliceRx.status}`);console.log(`- See: https://hashscan.io/${network}/transaction/${associateAliceTxSubmit.transactionId}`);// MANUAL ASSOCIATION FOR BOB'S ACCOUNTlet associateBobTx =awaitnewTokenAssociateTransaction().setAccountId(bobId).setTokenIds([tokenId]).freezeWith(client).sign(bobKey);let associateBobTxSubmit =awaitassociateBobTx.execute(client);let associateBobRx =awaitassociateBobTxSubmit.getReceipt(client);console.log(`\n- Bob NFT manual association: ${associateBobRx.status}`);console.log(`- See: https://hashscan.io/${network}/transaction/${associateBobTxSubmit.transactionId}`);// PART 2.1 STARTS ============================================================console.log(`\nPART 2.1 STARTS ============================================================`);// ENABLE TOKEN KYC FOR ALICE AND BOBlet [aliceKycRx, aliceKycTxId] =awaitkycEnableFcn(aliceId);let [bobKyc, bobKycTxId] =awaitkycEnableFcn(bobId);console.log(`\n- Enabling token KYC for Alice's account: ${aliceKycRx.status}`);console.log(`- See: https://hashscan.io/${network}/transaction/${aliceKycTxId}`);console.log(`\n- Enabling token KYC for Bob's account: ${bobKyc.status}`);console.log(`- See: https://hashscan.io/${network}/transaction/${bobKycTxId}`);67898;// DISABLE TOKEN KYC FOR ALICElet kycDisableTx =awaitnewTokenRevokeKycTransaction().setAccountId(aliceId).setTokenId(tokenId).freezeWith(client).sign(kycKey);// let kycDisableSubmitTx = await kycDisableTx.execute(client);// let kycDisableRx = await kycDisableSubmitTx.getReceipt(client);// console.log(`\n- Disabling token KYC for Alice's account: ${kycDisableRx.status}`);// console.log(`- See: https://hashscan.io/${network}/transaction/${kycDisableSubmitTx.transactionId}`);// QUERY TO CHECK INTIAL KYC KEYvar tokenInfo =awaittQueryFcn();console.log(`\n- KYC key for the NFT is: \n${tokenInfo.kycKey.toString()}`);// UPDATE TOKEN PROPERTIES: NEW KYC KEYlet tokenUpdateTx =awaitnewTokenUpdateTransaction().setTokenId(tokenId).setKycKey(newKycKey.publicKey).freezeWith(client).sign(adminKey);let tokenUpdateSubmitTx =awaittokenUpdateTx.execute(client);let tokenUpdateRx =awaittokenUpdateSubmitTx.getReceipt(client);console.log(`\n- Token update transaction (new KYC key): ${tokenUpdateRx.status}`);console.log(`- See: https://hashscan.io/${network}/transaction/${tokenUpdateSubmitTx.transactionId}`);// QUERY TO CHECK CHANGE IN KYC KEYvar tokenInfo =awaittQueryFcn();console.log(`\n- KYC key for the NFT is: \n${tokenInfo.kycKey.toString()}`);// PART 2.1 ENDS ============================================================console.log(`\nPART 2.1 ENDS ============================================================`);// BALANCE CHECK 1 oB =awaitbCheckerFcn(treasuryId); aB =awaitbCheckerFcn(aliceId); bB =awaitbCheckerFcn(bobId);console.log(`\n- Treasury balance: ${oB[0]} NFTs of ID: ${tokenId} and ${oB[1]}`);console.log(`- Alice balance: ${aB[0]} NFTs of ID: ${tokenId} and ${aB[1]}`);console.log(`- Bob balance: ${bB[0]} NFTs of ID: ${tokenId} and ${bB[1]}`);// 1st TRANSFER NFT Treasury -> Alicelet tokenTransferTx =awaitnewTransferTransaction().addNftTransfer(tokenId,2, treasuryId, aliceId).freezeWith(client).sign(treasuryKey);let tokenTransferSubmit =awaittokenTransferTx.execute(client);let tokenTransferRx =awaittokenTransferSubmit.getReceipt(client);console.log(`\n- NFT transfer Treasury -> Alice status: ${tokenTransferRx.status}`);console.log(`- See: https://hashscan.io/${network}/transaction/${tokenTransferSubmit.transactionId}`);// BALANCE CHECK 2 oB =awaitbCheckerFcn(treasuryId); aB =awaitbCheckerFcn(aliceId); bB =awaitbCheckerFcn(bobId);console.log(`\n- Treasury balance: ${oB[0]} NFTs of ID:${tokenId} and ${oB[1]}`);console.log(`- Alice balance: ${aB[0]} NFTs of ID:${tokenId} and ${aB[1]}`);console.log(`- Bob balance: ${bB[0]} NFTs of ID:${tokenId} and ${bB[1]}`);// 2nd NFT TRANSFER NFT Alice - >Boblet nftPrice =newHbar(10000000,HbarUnit.Tinybar); // 1 HBAR = 10,000,000 Tinybarlet tokenTransferTx2 =awaitnewTransferTransaction().addNftTransfer(tokenId,2, aliceId, bobId).addHbarTransfer(aliceId, nftPrice).addHbarTransfer(bobId,nftPrice.negated()).freezeWith(client).sign(aliceKey);let tokenTransferTx2Sign =awaittokenTransferTx2.sign(bobKey);let tokenTransferSubmit2 =awaittokenTransferTx2Sign.execute(client);let tokenTransferRx2 =awaittokenTransferSubmit2.getReceipt(client);console.log(`\n- NFT transfer Alice -> Bob status: ${tokenTransferRx2.status}`);console.log(`- See: https://hashscan.io/${network}/transaction/${tokenTransferSubmit2.transactionId}`);// BALANCE CHECK 3 oB =awaitbCheckerFcn(treasuryId); aB =awaitbCheckerFcn(aliceId); bB =awaitbCheckerFcn(bobId);console.log(`\n- Treasury balance: ${oB[0]} NFTs of ID:${tokenId} and ${oB[1]}`);console.log(`- Alice balance: ${aB[0]} NFTs of ID:${tokenId} and ${aB[1]}`);console.log(`- Bob balance: ${bB[0]} NFTs of ID:${tokenId} and ${bB[1]}`);// PART 2.2 STARTS ============================================================console.log(`\nPART 2.2 STARTS ============================================================`);// CREATE THE NFT TRANSFER FROM BOB -> ALICE TO BE SCHEDULED// REQUIRES ALICE'S AND BOB'S SIGNATURESlet txToSchedule =newTransferTransaction().addNftTransfer(tokenId,2, bobId, aliceId).addHbarTransfer(aliceId,nftPrice.negated()).addHbarTransfer(bobId, nftPrice);// SCHEDULE THE NFT TRANSFER TRANSACTION CREATED IN THE LAST STEPlet scheduleTx =awaitnewScheduleCreateTransaction().setScheduledTransaction(txToSchedule).execute(client);let scheduleRx =awaitscheduleTx.getReceipt(client);let scheduleId =scheduleRx.scheduleId;let scheduledTxId =scheduleRx.scheduledTransactionId;console.log(`\n- The schedule ID is: ${scheduleId}`);console.log(`- The scheduled transaction ID is: ${scheduledTxId}`);// SUBMIT ALICE'S SIGNATURE FOR THE TRANSFER TRANSACTIONlet aliceSignTx =awaitnewScheduleSignTransaction().setScheduleId(scheduleId).freezeWith(client).sign(aliceKey);let aliceSignSubmit =awaitaliceSignTx.execute(client);let aliceSignRx =awaitaliceSignSubmit.getReceipt(client);console.log(`\n- Status of Alice's signature submission: ${aliceSignRx.status}`);console.log(`- See: https://hashscan.io/${network}/transaction/${aliceSignSubmit.transactionId}`);// QUERY TO CONFIRM IF THE SCHEDULE WAS TRIGGERED (SIGNATURES HAVE BEEN ADDED) scheduleQuery =awaitnewScheduleInfoQuery().setScheduleId(scheduleId).execute(client);console.log(`\n- Schedule triggered (all required signatures received): ${scheduleQuery.executed !==null}`);// SUBMIT BOB'S SIGNATURE FOR THE TRANSFER TRANSACTIONlet bobSignTx =awaitnewScheduleSignTransaction().setScheduleId(scheduleId).freezeWith(client).sign(bobKey);let bobSignSubmit =awaitbobSignTx.execute(client);let bobSignRx =awaitbobSignSubmit.getReceipt(client);console.log(`\n- Status of Bob's signature submission: ${bobSignRx.status}`);console.log(`- See: https://hashscan.io/${network}/transaction/${bobSignSubmit.transactionId}`);// QUERY TO CONFIRM IF THE SCHEDULE WAS TRIGGERED (SIGNATURES HAVE BEEN ADDED) scheduleQuery =awaitnewScheduleInfoQuery().setScheduleId(scheduleId).execute(client);console.log(`\n- Schedule triggered (all required signatures received): ${scheduleQuery.executed !==null}`);// VERIFY THAT THE SCHEDULED TRANSACTION (TOKEN TRANSFER) EXECUTED oB =awaitbCheckerFcn(treasuryId); aB =awaitbCheckerFcn(aliceId); bB =awaitbCheckerFcn(bobId);console.log(`\n- Treasury balance: ${oB[0]} NFTs of ID: ${tokenId} and ${oB[1]}`);console.log(`- Alice balance: ${aB[0]} NFTs of ID: ${tokenId} and ${aB[1]}`);console.log(`- Bob balance: ${bB[0]} NFTs of ID: ${tokenId} and ${bB[1]}`);// PART 3 ============================================================console.log(`\nPART 3 STARTS ============================================================`);// PAUSE ALL TOKEN OEPRATIONSlet tokenPauseTx =awaitnewTokenPauseTransaction().setTokenId(tokenId).freezeWith(client).sign(pauseKey);let tokenPauseSubmitTx =awaittokenPauseTx.execute(client);let tokenPauseRx =awaittokenPauseSubmitTx.getReceipt(client);console.log(`\n- Token pause: ${tokenPauseRx.status}`);console.log(`- See: https://hashscan.io/${network}/transaction/${tokenPauseSubmitTx.transactionId}`);// TEST THE TOKEN PAUSE BY TRYING AN NFT TRANSFER (TREASURY -> ALICE)let tokenTransferTx3 =awaitnewTransferTransaction().addNftTransfer(tokenId,3, treasuryId, aliceId).freezeWith(client).sign(treasuryKey);let tokenTransferSubmit3 =awaittokenTransferTx3.execute(client);try {let tokenTransferRx3 =awaittokenTransferSubmit3.getReceipt(client);console.log(`\n- NFT transfer Treasury -> Alice status: ${tokenTransferRx3.status}`); } catch {// TOKEN QUERY TO CHECK PAUSEvar tokenInfo =awaittQueryFcn();console.log(`\n- NFT transfer unsuccessful: Token ${tokenId} is paused (${tokenInfo.pauseStatus})`);console.log(`- See: https://hashscan.io/${network}/transaction/${tokenTransferSubmit3.transactionId}`); }// UNPAUSE ALL TOKEN OEPRATIONSlet tokenUnpauseTx =awaitnewTokenUnpauseTransaction().setTokenId(tokenId).freezeWith(client).sign(pauseKey);let tokenUnpauseSubmitTx =awaittokenUnpauseTx.execute(client);let tokenUnpauseRx =awaittokenUnpauseSubmitTx.getReceipt(client);console.log(`\n- Token unpause: ${tokenUnpauseRx.status}`);console.log(`- See: https://hashscan.io/${network}/transaction/${tokenUnpauseSubmitTx.transactionId}`);// FREEZE ALICE'S ACCOUNT FOR THIS TOKENlet tokenFreezeTx =awaitnewTokenFreezeTransaction().setTokenId(tokenId).setAccountId(aliceId).freezeWith(client).sign(freezeKey);let tokenFreezeSubmitTx =awaittokenFreezeTx.execute(client);let tokenFreezeRx =awaittokenFreezeSubmitTx.getReceipt(client);console.log(`\n- Freeze Alice's account for token ${tokenId}: ${tokenFreezeRx.status}`);console.log(`- See: https://hashscan.io/${network}/transaction/${tokenFreezeSubmitTx.transactionId}`);// TEST THE TOKEN FREEZE FOR THE ACCOUNT BY TRYING A TRANSFER (ALICE -> BOB)let tokenTransferTx4 =awaitnewTransferTransaction().addNftTransfer(tokenId,2, aliceId, bobId).addHbarTransfer(aliceId, nftPrice).addHbarTransfer(bobId,nftPrice.negated()).freezeWith(client).sign(aliceKey);let tokenTransferTx4Sign =awaittokenTransferTx4.sign(bobKey);let tokenTransferSubmit4 =awaittokenTransferTx4Sign.execute(client);try {let tokenTransferRx4 =awaittokenTransferSubmit4.getReceipt(client);console.log(`\n- NFT transfer Alice -> Bob status: ${tokenTransferRx4.status}`); } catch {console.log(`\n- NFT transfer Alice -> Bob unsuccessful: Alice's account is frozen for this token`);console.log(`- See: https://hashscan.io/${network}/transaction/${tokenTransferSubmit4.transactionId}`); }// UNFREEZE ALICE'S ACCOUNT FOR THIS TOKENlet tokenUnfreezeTx =awaitnewTokenUnfreezeTransaction().setTokenId(tokenId).setAccountId(aliceId).freezeWith(client).sign(freezeKey);let tokenUnfreezeSubmitTx =awaittokenUnfreezeTx.execute(client);let tokenUnfreezeRx =awaittokenUnfreezeSubmitTx.getReceipt(client);console.log(`\n- Unfreeze Alice's account for token ${tokenId}: ${tokenUnfreezeRx.status}`);console.log(`- See: https://hashscan.io/${network}/transaction/${tokenUnfreezeSubmitTx.transactionId}`);// WIPE THE TOKEN FROM ALICE'S ACCOUNTlet tokenWipeTx =awaitnewTokenWipeTransaction().setAccountId(aliceId).setTokenId(tokenId).setSerials([2]).freezeWith(client).sign(wipeKey);let tokenWipeSubmitTx =awaittokenWipeTx.execute(client);let tokenWipeRx =awaittokenWipeSubmitTx.getReceipt(client);console.log(`\n- Wipe token ${tokenId} from Alice's account: ${tokenWipeRx.status}`);console.log(`- See: https://hashscan.io/${network}/transaction/${tokenWipeSubmitTx.transactionId}`);// CHECK ALICE'S BALANCE aB =awaitbCheckerFcn(aliceId);console.log(`\n- Alice balance: ${aB[0]} NFTs of ID:${tokenId} and ${aB[1]}`);// TOKEN QUERY TO CHECK TOTAL TOKEN SUPPLYvar tokenInfo =awaittQueryFcn();console.log(`- Current NFT supply: ${tokenInfo.totalSupply}`);// DELETE THE TOKENlet tokenDeleteTx =newTokenDeleteTransaction().setTokenId(tokenId).freezeWith(client);let tokenDeleteSign =awaittokenDeleteTx.sign(adminKey);let tokenDeleteSubmitTx =awaittokenDeleteSign.execute(client);let tokenDeleteRx =awaittokenDeleteSubmitTx.getReceipt(client);console.log(`\n- Delete token ${tokenId}: ${tokenDeleteRx.status}`);console.log(`- See: https://hashscan.io/${network}/transaction/${tokenDeleteSubmitTx.transactionId}`);// TOKEN QUERY TO CHECK DELETIONvar tokenInfo =awaittQueryFcn();console.log(`\n- Token ${tokenId} is deleted: ${tokenInfo.isDeleted}`);console.log(`\n- THE END ============================================================`);console.log(`\n- 👇 Go to:`);console.log(`- 🔗 www.hedera.com/discord\n`);client.close();// ACCOUNT CREATOR FUNCTION ==========================================asyncfunctionaccountCreateFcn(pvKey, iBal, client) {constresponse=awaitnewAccountCreateTransaction().setInitialBalance(iBal).setKey(pvKey.publicKey).setMaxAutomaticTokenAssociations(10).execute(client);constreceipt=awaitresponse.getReceipt(client);return [receipt.status,receipt.accountId]; }// TOKEN MINTER FUNCTION ==========================================asyncfunctiontokenMinterFcn(CIDs) {let mintTx =newTokenMintTransaction().setTokenId(tokenId).setMetadata(CIDs).freezeWith(client);let mintTxSign =awaitmintTx.sign(supplyKey);let mintTxSubmit =awaitmintTxSign.execute(client);let mintRx =awaitmintTxSubmit.getReceipt(client);return [mintRx,mintTxSubmit.transactionId]; }// BALANCE CHECKER FUNCTION ==========================================asyncfunctionbCheckerFcn(id) { balanceCheckTx =awaitnewAccountBalanceQuery().setAccountId(id).execute(client);return [balanceCheckTx.tokens._map.get(tokenId.toString()),balanceCheckTx.hbars]; }// KYC ENABLE FUNCTION ==========================================asyncfunctionkycEnableFcn(id) {let kycEnableTx =awaitnewTokenGrantKycTransaction().setAccountId(id).setTokenId(tokenId).freezeWith(client).sign(kycKey);let kycSubmitTx =awaitkycEnableTx.execute(client);let kycRx =awaitkycSubmitTx.getReceipt(client);return [kycRx,kycSubmitTx.transactionId]; }// TOKEN QUERY FUNCTION ==========================================asyncfunctiontQueryFcn() {var tokenInfo =awaitnewTokenInfoQuery().setTokenId(tokenId).execute(client);return tokenInfo; }}main();