uint? For example uint256 with uint16 or better to use one type?
Unsigned integers (uint) are similar to integers, but they can only store positive values. Like integers, unsigned integers can be declared with a number of bits, such as uint8, uint16, uint32, uint64, and so on, up to uint256.
It depends what you're trying to do and what you expect to be the maximum uint in your arithmetic's. Using smaller uint's are more gas efficient.
for example this function function calculate(uint256 a, uint16 b) public view returns (uint256 memory) { uint256 result = a * b - a; return result; } is it safe?
That would depend on what you're calculating there, if its Token amounts, NO its not. For Tokens minimum use uint128.
What are you multiplying the Token amount with? I suppose this is a percentage? And always close your logic in brackets for any case uint256 result = (a * b) - a;
yes, it's like the loan calculator. User enters the amount of tokens and the percentage
Then its fine, if you dont expect "b" to ever go over 65,535, should work as good and even a soft stopper for anyone adding anything above.
Обсуждают сегодня