简体   繁体   English

我无法使用@hashgraph/sdk hedera npm 转移 NFT。 如何使用 @hashgraph/sdk 的内置方法传输 nft?

[英]I am not be able to transfer NFT using @hashgraph/sdk hedera npm. How to transfer nft using @hashgraph/sdk's in built method?

I am not able to transfer NFT using @hashgraph/SDK hedera npm.我无法使用@hashgraph/SDK hedera npm 转移 NFT。 How to transfer nft using @hashgraph/SDK's inbuilt method?如何使用@hashgraph/SDK 的内置方法传输 nft?

Also, Nft is already associated with the seller account.此外,Nft 已经与卖家账户相关联。

Also, I am transferring token which is available in hashpack nft section.另外,我正在传输 hashpack nft 部分中提供的令牌。

I am getting the below error on calling the TransferTransaction method of @hashgraph/sdk@2.17.1 .我在调用@hashgraph/sdk@2.17.1TransferTransaction方法时收到以下错误。 Code:代码:

  const TransferNft = async (tokenId, sellerAccount, sellerId, buyerAccount, buyerId) => {
  try {
    const client = await getClient();

    tokenId = TokenId.fromString(tokenId);

    let sellerKey = await getPrivateKey(sellerId);
    sellerKey = PrivateKey.fromString(sellerKey);

    let buyerKey = await getPrivateKey(buyerId);
    buyerKey = PrivateKey.fromString(buyerKey);

    // 2nd NFT TRANSFER NFT Alice->Bob
    let tokenTransferTx2 = await new TransferTransaction()
      .addNftTransfer(tokenId, 2, sellerAccount, buyerAccount)
      .addHbarTransfer(sellerAccount, Hbar.fromTinybars(100))
      .addHbarTransfer(buyerAccount, Hbar.fromTinybars(-100))
      .freezeWith(client)
      .sign(sellerKey);
    let tokenTransferTx2Sign = await tokenTransferTx2.sign(buyerKey);
    let tokenTransferSubmit2 = await tokenTransferTx2Sign.execute(client);
    let tokenTransferRx2 = await tokenTransferSubmit2.getReceipt(client);
    console.log(`\n NFT transfer Alice->Bob status: ${tokenTransferRx2.status} \n`);

    return tokenTransferRx2.status;
  } catch (error) {
    console.log('Error in HederaToken/TransferNft/TransferNft: \n', error)
  }
};

receipt for transaction 0.0.40217130@1663228521.315536859 contained error status TOKEN_NOT_ASSOCIATED_TO_ACCOUNT交易 0.0.40217130@1663228521.315536859 的收据包含错误状态 TOKEN_NOT_ASSOCIATED_TO_ACCOUNT

Error:错误: 在此处输入图像描述

Before an account that is not the treasury for an HTS token can receive or send a specific token ID, they must be “associated” with the token — this helps reduce unwanted spam and other concerns from users that don't want to be associated with any of the variety of tokens that are created on the Hedera network.在不是 HTS 令牌库的帐户可以接收或发送特定令牌 ID 之前,它们必须与令牌“关联”——这有助于减少不希望的垃圾邮件和其他不想关联的用户的担忧在 Hedera 网络上创建的各种代币。

This association between an account and a token ID can be done in two ways, manually or automatically.帐户和令牌 ID 之间的这种关联可以通过手动或自动两种方式完成。 Note that automatic associations can be done for both existing and newly created accounts.请注意,可以对现有帐户和新创建的帐户进行自动关联。

Here's how you would do an auto-association for an existing account via an account update:以下是您如何通过帐户更新对现有帐户进行自动关联:

 // AUTO-ASSOCIATION FOR ALICE'S ACCOUNT
    let associateTx = await new AccountUpdateTransaction()
        .setAccountId(aliceId)
        .setMaxAutomaticTokenAssociations(100)
        .freezeWith(client)
        .sign(aliceKey);
    let associateTxSubmit = await associateTx.execute(client);
    let associateRx = await associateTxSubmit.getReceipt(client);
    console.log(`Alice NFT Auto-Association: ${associateRx.status} \n`);

Here's how you would do a manual association for an existing account:以下是对现有帐户进行手动关联的方法:

// MANUAL ASSOCIATION FOR BOB'S ACCOUNT
let associateBobTx = await new TokenAssociateTransaction()
    .setAccountId(bobId)
    .setTokenIds([tokenId])
    .freezeWith(client)
    .sign(bobKey);
let associateBobTxSubmit = await associateBobTx.execute(client);
let associateBobRx = await associateBobTxSubmit.getReceipt(client);
console.log(`Bob NFT Manual Association: ${associateBobRx.status} \n`);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Alchemy web3 SDK 获取有关 NFT 合约的信息? - How to get information about an NFT contract using Alchemy web3 SDK? 如何仅使用 dApp 限制 NFT 铸造 - How to restrict NFT minting using the dApp only 如何使用炼金术发送已经铸造的 NFT - How to send already minted NFT using alchemy 使用JavaScript SDK的预签名URL的AWS Transfer Acceleration - AWS Transfer Acceleration with pre-signed URLs using JavaScript SDK 使用 npm 安装 express 时出现问题。 - Problems installing express using npm. 通过 JS API 在 OpenSea 上列出 NFT:无法提取传输调用数据错误 400 - Listing NFT on OpenSea via JS API: Failed to extract transfer calldata Error 400 使用 npm 安装 jquery、angularjs 等包时出现错误显示。 - Error show for installing a package like jquery,angularjs using npm. 我正在使用 docusign-esign 节点 SDK,我想更改发件人的姓名(截至目前,docusign 使用与帐户关联的名称) - I am using docusign-esign node SDK and i want to change the Sender's name(as of now docusign using the Name associated with the account) 如何使用npm中的alexa-sdk将LaunchRequest委托给IntentRequest - How can I delegate the LaunchRequest to an IntentRequest using the alexa-sdk from npm 如何使用 AW S3 SDK 的 createPresignedPost 方法公开访问 AWS S3 文件? - How to make an AWS S3 file public accessible using AW S3 SDK's createPresignedPost method?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM