EmmBee
EmmBee

Reputation: 169

How do I send HBAR to an Account on Hedera?

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 [email protected] failed precheck with status INVALID_ACCOUNT_AMOUNTS

Upvotes: 0

Views: 215

Answers (1)

Pathorn Teng
Pathorn Teng

Reputation: 513

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

Upvotes: 2

Related Questions