簡體   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?

我無法使用@hashgraph/SDK hedera npm 轉移 NFT。 如何使用@hashgraph/SDK 的內置方法傳輸 nft?

此外,Nft 已經與賣家賬戶相關聯。

另外,我正在傳輸 hashpack nft 部分中提供的令牌。

我在調用@hashgraph/sdk@2.17.1TransferTransaction方法時收到以下錯誤。 代碼:

  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)
  }
};

交易 0.0.40217130@1663228521.315536859 的收據包含錯誤狀態 TOKEN_NOT_ASSOCIATED_TO_ACCOUNT

錯誤: 在此處輸入圖像描述

在不是 HTS 令牌庫的帳戶可以接收或發送特定令牌 ID 之前,它們必須與令牌“關聯”——這有助於減少不希望的垃圾郵件和其他不想關聯的用戶的擔憂在 Hedera 網絡上創建的各種代幣。

帳戶和令牌 ID 之間的這種關聯可以通過手動或自動兩種方式完成。 請注意,可以對現有帳戶和新創建的帳戶進行自動關聯。

以下是您如何通過帳戶更新對現有帳戶進行自動關聯:

 // 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`);

以下是對現有帳戶進行手動關聯的方法:

// 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM