0

I've been trying to send hbar to an account and I get this error, what am I doing wrong?

 await new TransferTransaction()
        .addHbarTransfer(AccountId.fromString("0.0.XXXXXXXX"), new Hbar(1))
        .execute(client);

But it fails with this error:

PrecheckStatusError: transaction 0.0.xxxxxxx@1677810990.286133522 failed precheck with status INVALID_ACCOUNT_AMOUNTS
EmmBee
  • 114
  • 5

1 Answers1

1

For Hedera, you need to specify both sending and receiving account. The total sum of amounts in a transaction must be 0.

const sendHbar = await new TransferTransaction()
 .addHbarTransfer(sendingAccountId, Hbar.fromTinybars(-1)) //Sending account
 .addHbarTransfer(receivingAccountId, Hbar.fromTinybars(1)) //Receiving account
 .execute(client);

Please take a look at the following link for more info https://docs.hedera.com/hedera/getting-started/transfer-hbar

Pathorn Teng
  • 411
  • 6