How to store cryptocurrency balance in mysql?



Referred to this question. In the marked answer said that the best way to store cryptocurrency in mysql is to store it as DECIMAL(27,18) or DECIMAL(36,18). But comment there makes me doubt. If ETH value has 32 bytes, then we can’t store balance in this way. So what is the best way to store it?

P.S. Except strings, I need to sort wallets by its balance value.


The design of the Ethereum VM has nothing to do with what you need to represent an ETH amount.

1 ETH is represented by 10^18 of its natural unit ( 1 Ether = 1,000,000,000,000,000,000 wei ).

You’ll need, at most, DECIMAL(36,18) which is huge enough to accommodate any conceivable amount at the required precision level.

The Ethereum VM only has a 256-bit (32-byte) numerical type for reasons that are never fully articulated, so internally that’s what it has to use for amount values.

Answered By – tadman

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More