Hedera Invalid Signature

667 Views Asked by At

I'm learning to do a minting dApp, it works fine when I mint, associate, transfer...

But now when I wanted to add hbarTransfer, I have invalid signature

What makes it don't work between this that works :

let tokenTransferTx = await new TransferTransaction()
    .addNftTransfer('0.0.47855058', restenft, treasuryId, accountId)
    .freezeWith(client)
    .sign(treasuryKey);

let tokenTransferSubmit = await tokenTransferTx.execute(client);
let tokenTransferRx = await tokenTransferSubmit.getReceipt(client);

And this by just adding hbarTransfer

let tokenTransferTx = await new TransferTransaction()
    .addNftTransfer('0.0.47855058', restenft, treasuryId, accountId)
    .addHbarTransfer(AccountId.fromString(accountId), -200)
    .addHbarTransfer(AccountId.fromString('0.0.47853116'), 200)
    .freezeWith(client)
    .sign(treasuryKey);

let tokenTransferSubmit = await tokenTransferTx.execute(client);
let tokenTransferRx = await tokenTransferSubmit.getReceipt(client);

2

There are 2 best solutions below

0
On BEST ANSWER

All sender accounts (the accounts that are being debited from) are required to sign the transaction. In the second code snippet you would need to sign with the private key for account 0.0.47853116.

let tokenTransferTx = await new TransferTransaction()
    .addNftTransfer('0.0.47855058', restenft, treasuryId, accountId)
    .addHbarTransfer(AccountId.fromString(accountId), -200)
    .addHbarTransfer(AccountId.fromString('0.0.47853116'), 200)
    .freezeWith(client)
    .sign(treasuryKey)
    .sign(accountKey);
0
On

Simi is correct. Any account with a balance being deducted in a transaction must have the account key sign (approve) that transaction.

That includes token and HBAR transfers, and fee structures for tokens (whether it's fixed fees, royalty fees, or fallback fees).