I am not able to transfer NFT using @hashgraph/SDK hedera npm. How to transfer nft using @hashgraph/SDK's inbuilt method?
Also, Nft is already associated with the seller account.
Also, I am transferring token which is available in hashpack nft section.
I am getting the below error on calling the TransferTransaction
method of @hashgraph/sdk@2.17.1
.
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