[英]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.1
的TransferTransaction
方法时收到以下错误。 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
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.