Skip to content

BUG: Developer Playground -> Misc -> Transactions -> NFT ID #2

Description

@Luke-Forrest

Incorrect code used for this one. The following code:

const {
    AccountId,
    PrivateKey,
    Client,
    NftId,
    TokenNftInfoQuery
  } = require("@hashgraph/sdk"); // v2.46.0

async function main() {
  let client;
  try {
    // Your account ID and private key from string value
    const MY_ACCOUNT_ID = AccountId.fromString("<AccountId>");
    const MY_PRIVATE_KEY = PrivateKey.fromStringECDSA("<PrivateKey>");

    // Pre-configured client for test network (testnet)
    client = Client.forTestnet();

    //Set the operator with the account ID and private key
    client.setOperator(MY_ACCOUNT_ID, MY_PRIVATE_KEY);

    // Start your code here
  
    
    const nftId = new NftId(new TokenId(0,0,2), 56562);
    console.log("------------------------------ NFT ID ------------------------------ ");
    console.log("NFT ID                 : ", nftId.toString());
      
  } catch (error) {
    console.error(error);
  } finally {
    if (client) client.close();
  }
}

main();

This should be:

const {
  AccountId,
  PrivateKey,
  Client,
  NftId,
  TokenId
} = require("@hashgraph/sdk"); // v2.46.0

async function main() {
  let client;
  try {
    // Your account ID and private key from string value
    const MY_ACCOUNT_ID = AccountId.fromString("<AccountID>");
    const MY_PRIVATE_KEY = PrivateKey.fromStringECDSA("<PrivateKey>");

    // Pre-configured client for test network (testnet)
    client = Client.forTestnet();

    //Set the operator with the account ID and private key
    client.setOperator(MY_ACCOUNT_ID, MY_PRIVATE_KEY);

    // Start your code here


    const nftId = new NftId(new TokenId(0, 0, 2), 56562);
    console.log("------------------------------ NFT ID ------------------------------ ");
    console.log("NFT ID                 : ", nftId.toString());

  } catch (error) {
    console.error(error);
  } finally {
    if (client) client.close();
  }
}

main();

Changes:

  • Removed: TokenNftInfoQuery
  • Added: TokenId

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions