uint256 in mysql

what's the most sane way to store an amount like this in a db? Decimal(38,18), a bigint of wei like Decimal(38,0), a hex string like binary(20), varchar (lol), something else?
1 Reply
whatplan
whatplan2y ago
I am not that familiar with this, but heres what chatgpt had to say if it helps at all
Decimal(38,18): This is a good option if you want to store the value with precision up to 18 decimal places, which is the same as the precision of Ethereum's smallest denomination (wei). Bigint: You could also store the value as a bigint, which can store up to 20 digits. This would require converting the uint256 value to a string and then storing it as an integer. However, this approach would lose precision beyond the first 20 digits. Hex string: You could store the value as a hexadecimal string, which can represent the full 256-bit uint256 value in 64 characters. This approach would preserve the full precision of the uint256 value, but may make querying and indexing more difficult. VarChar: You could store the value as a VarChar. This approach would be flexible in terms of the length of the value that could be stored. However, it may require additional parsing and casting operations when working with the data. Ultimately, the best option will depend on your specific use case and the requirements of your application. If you require full precision and plan to perform mathematical operations with the data, Decimal(38,18) is a good option. If you are primarily storing the data for display or retrieval purposes, a hex string or VarChar may be more suitable.
Want results from more Discord servers?
Add your server