Skip to content

Commit

Permalink
chore: update update-nfts-metadata-of-non-fungible-token.js (#2266)
Browse files Browse the repository at this point in the history
* Update update-nfts-metadata-of-non-fungible-token.js

Signed-off-by: SimiHunjan <[email protected]> 

Signed-off-by: SimiHunjan <[email protected]>

* chore: removed commented code, improved comments on setMaxAutomaticTokenAssociations

Signed-off-by: Alexander Gadzhalov <[email protected]>

* chore: refactored open to opened

Signed-off-by: Alexander Gadzhalov <[email protected]>

---------

Signed-off-by: SimiHunjan <[email protected]>
Signed-off-by: Alexander Gadzhalov <[email protected]>
Co-authored-by: Alexander Gadzhalov <[email protected]>
  • Loading branch information
SimiHunjan and agadzhalov authored Apr 23, 2024
1 parent 21deae3 commit 5d00b72
Showing 1 changed file with 2 additions and 17 deletions.
19 changes: 2 additions & 17 deletions examples/update-nfts-metadata-of-non-fungible-token.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
AccountCreateTransaction,
Hbar,
TransferTransaction,
TokenAssociateTransaction,
} from "@hashgraph/sdk";
import dotenv from "dotenv";

Expand Down Expand Up @@ -103,10 +102,10 @@ async function main() {
nftInfo = tokenNftsInfo[0];
console.log(`Set token NFT metadata:`, nftInfo.metadata);

// Create an account to transfer the NFT to
// Create an account with 10 automatic token association slots to transfer the NFT to
const accountCreateTx = new AccountCreateTransaction()
.setKey(operatorKey)
.setMaxAutomaticTokenAssociations(10)
.setMaxAutomaticTokenAssociations(10) // If the account does not have any automatic token association slots opened ONLY then associate the NFT to the account
.setInitialBalance(new Hbar(100))
.freezeWith(client);

Expand All @@ -118,20 +117,6 @@ async function main() {
const newAccountId = accountCreateTxReceipt.accountId;
console.log(`New account id: ${newAccountId.toString()}`);

const tokenAssociateTx = new TokenAssociateTransaction()
.setAccountId(newAccountId)
.setTokenIds([tokenId])
.freezeWith(client);

const tokenAssociateTxResponse = await (
await tokenAssociateTx.sign(operatorKey)
).execute(client);
const tokenAssociateTxReceipt =
await tokenAssociateTxResponse.getReceipt(client);
console.log(
`Status of token associate transaction: ${tokenAssociateTxReceipt.status.toString()}`,
);

// Transfer nft to the new account
const transferNftTx = new TransferTransaction()
.addNftTransfer(tokenId, nftSerial, operatorId, newAccountId)
Expand Down

0 comments on commit 5d00b72

Please sign in to comment.