添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
VelvetShark

Max values for each uint in Solidity, from uint8 to uint256

Published on

Sream by Darren Almond

If you often struggle to remember which uint has what max value in Solidity, as I do, this is a cheatsheet for you (and for me, I'll probably use it all the time).

Gas is expensive on Ethereum so it's best to optimize for it and not to use variables that are larger than what we need. If all we are going to store in a variable are numbers from 1 to max 100, it doesn't make sense to use uint256. It's a waste of gas and money.

I always struggle to remember what's the maximum value for each uint, so I've created a cheatsheet. Now I won't have to worry if my chosen uint is going to be enough or too small.

Below, (almost) all the max values for each uint. I've added the number of digits for each value, so for example, if you know that your max value will have no more than 12 digits, you can safely choose uint40, which has 13 digits.

I didn't include anything between uint128 and uint256. If you're going to use such large numbers, you'll probably use uint256 by default.

A few things to know/remember: