In Part 1 of the series, you saw how to mint and transfer an NFT using the Hedera Token Service (HTS). Now, in Part 2, you will see how to take advantage of the flexibility you get when you create and configure your tokens with HTS. More specifically, you will learn how to:
Enable and disable a KYC flag for a token (KYC stands for βknow your customerβ)
Update token properties (only possible if itβs a mutable token. Hint: AdminKey)
Schedule transactions (like a token transfer)
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.
β If you want the entire code used for this tutorial, skip to the Code Check section below.
Understanding KYC and Hedera Tokens
KYC Key
When you create a token with HTS, you can optionally use the .setKycKey(<key>) method to enable this <key> to grant (or revoke) the KYC status of other accounts so they can transact with your token. You would consider using the KYC flag when you need your token to be used only within parties that have been βauthorizedβ to use it. For instance, known registered users or those who have passed identity verification. Think of this as identity and compliance features like anti-money laundering (AML) requirements or any type of off-ledger authentication mechanism, like if a user has signed up for your application.
The .setKycKey(<key>) method is not required when you create your token, so if you donβt use the method that means anyone who is associated with your token can transact without having to be βauthorizedβ. No KYC key also means that KYC grant or revoke operations are not possible for the token in the future.
Enable Token KYC on an Account
We will continue with the NFT example from Part 1. However, we must create a new token using .setKycKey(<key>). Before users can transfer the newly created token, we must grant KYC to those users, namely Alice and Bob.
nft-part2.js
// 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}`);
-EnablingtokenKYCforAlice's account: SUCCESS- See: https://hashscan.io/testnet/transaction/0.0.2520793@1723765780.358402849- Enabling token KYC for Bob'saccount:SUCCESS-See:https://hashscan.io/testnet/transaction/0.0.2520793@1723765782.680313758
Disable Token KYC on an Account
After the KYC flag has been set to true for a user, the administrator, identity provider, or compliance manager can revoke or disable the KYC flag. After KYC is disabled for a user, he or she can no longer receive or send that token. Hereβs a sample code for disabling token KYC on Aliceβs account:
Note: The following sections require Alice to have token KYC enabled.
Updating tokens
If you create a token using the .setAdminKey(<key>) method, then you can βupdateβ that token, meaning change its metadata and characteristics. For instance, you can change the token name, symbol, or the keys that are associated with its controlled mutability. You could create a token that initially has a 1-to-1 key for minting and burning and, over time, change this to a threshold or multi-signature key. You can rotate the keys associated with compliance and administration or even remove them entirely, offering a more decentralized approach over time.
On the other hand, if you create a token without using .setAdminKey(<key>), that token is immutable, and its properties cannot be modified.
In our example, we start by checking the initial KYC key for the token, then we update the KYC key from <kycKey> to <newKycKey>, and then we query the token again to make sure the key change took place.
nft-part2.js
// QUERY TO CHECK INITIAL 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()}`);
// TOKEN QUERY FUNCTION ==========================================asyncfunctiontQueryFcn() {var tokenInfo =awaitnewTokenInfoQuery().setTokenId(tokenId).execute(client);return tokenInfo;}
Console output:
-KYCkeyfortheNFTis:302a300506032b65700321009178c6063f1ba8a61bf7e9674edf2aee06d547e0c18d0bb-Tokenupdatetransaction (new KYCkey): SUCCESS-See:https://hashscan.io/testnet/transaction/0.0.2520793@1723765784.825417112-KYCkeyfortheNFTis:302a300506032b65700321001bfd2a1a63e5b7e5e159ca0911db29fb6013074b1652a253
Schedule Transactions
Scheduled transactions enable you to collect the required signatures for a transaction in preparation for its execution. This can be useful if you donβt have all the required signatures for the network to immediately process the transaction. Currently, you can schedule: TransferTransaction() (for hbar and HTS tokens), TokenMintTransaction(), TokenBurnTransaction(), and TopicMessageSubmitTransaction(). More transactions are supported with new releases.
Now, we will schedule a token transfer from Bob to Alice using scheduled transactions. This token transfer requires signatures from both parties.
Given that Aliceβs and Bobβs signatures are not immediately available (for the purposes of this example), we first create the NFT transfer without signatures. Then, we create the scheduled transaction using the constructor ScheduleCreateTransaction() and specify the NFT transfer as the transaction to schedule using the .setScheduledTransaction() method.
nft-part2.js
// 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(`- The schedule ID is: ${scheduleId}`);console.log(`- The scheduled transaction ID is: ${scheduledTxId} \n`);
The token transfer is now scheduled, and it will be executed as soon as all required signatures are submitted. Note that the scheduled transaction IDs (scheduledTxId in this case) have a βscheduledβ flag that you can use to confirm the status of the transaction.
As of the time of this writing, a scheduled transaction has 30 minutes to collect all the required signatures before it can be executed or it expires (deleted from the network). If you set an <AdminKey> for the scheduled transaction, then you can delete it before its execution or expiration.
// 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(`- 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(`- 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(`- 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}`);
Console output:
-StatusofAlice's signature submission: SUCCESS- See: https://hashscan.io/testnet/transaction/0.0.2520793@@1723765792.396881487- Schedule triggered (all required signatures received): false- Status of Bob'ssignaturesubmission:SUCCESS-See:https://hashscan.io/testnet/transaction/0.0.2520793@@1723765789.984805782-Scheduletriggered (all requiredsignaturesreceived): true
The scheduled transaction was executed. It is still a good idea to verify that the transfer happened as we expected, so we check all the balances once more to confirm.
nft-part2.js
// VERIFY THAT THE SCHEDULED TRANSACTION (TOKEN TRANSFER) EXECUTEDoB =awaitbCheckerFcn(treasuryId);aB =awaitbCheckerFcn(aliceId);bB =awaitbCheckerFcn(bobId);console.log(`- 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]}`);
// BALANCE CHECKER FUNCTION ==========================================asyncfunctionbCheckerFcn(id) { balanceCheckTx =awaitnewAccountBalanceQuery().setAccountId(id).execute(client);return [balanceCheckTx.tokens._map.get(tokenId.toString()),balanceCheckTx.hbars]; }
Console output:
Conclusion
In this article, you saw examples of the flexibility you get when you create and configure your tokens with HTS - in a transparent and cryptographically provable way. Take advantage of this flexibility to tackle entirely new opportunities in the tokenization industry!
Code Check β
nft-part2.js
console.clear();require("dotenv").config();const {AccountId,PrivateKey,Client,TokenCreateTransaction,TokenInfoQuery,TokenType,CustomRoyaltyFee,CustomFixedFee,Hbar,HbarUnit,TokenSupplyType,TokenMintTransaction,TokenBurnTransaction,TransferTransaction,AccountBalanceQuery,TokenAssociateTransaction,TokenUpdateTransaction,TokenGrantKycTransaction,TokenRevokeKycTransaction,ScheduleCreateTransaction,ScheduleSignTransaction,ScheduleInfoQuery,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 COLLECTION let tokenBurnTx = await new TokenBurnTransaction().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 ACCOUNT let associateAliceTx = await new TokenAssociateTransaction().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 ACCOUNT let associateBobTx = await new TokenAssociateTransaction().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 ALICE let kycDisableTx = await new TokenRevokeKycTransaction().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 KEY let tokenUpdateTx = await new TokenUpdateTransaction().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 -> Alice let tokenTransferTx = await new TransferTransaction().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]}`);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 = await new TokenGrantKycTransaction().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();