Post
Topic
Board Development & Technical Discussion
Merits 1 from 1 user
Re: "Amount in satoshis can be negative", How true ?
by
Ejarwan
on 12/11/2024, 19:28:08 UTC
⭐ Merited by vapourminer (1)
Hey,

You're right that CAmount is a signed 64-bit integer, which technically allows for negative values. However, in practice, Bitcoin transactions won't have negative amounts—those would just get rejected by the MoneyRange function.

The reason they use a signed integer is mostly for flexibility, especially when handling wallet balances. For example, if you’re tracking the net effect of transactions on your wallet, it could temporarily show a negative value (like fees deducted before funds are added). But on-chain amounts themselves always need to be non-negative.

So, the code allows for negative numbers internally, but anything that's actually a transaction amount will always be checked to make sure it’s non-negative.

Hope this clears it up!