Linked Questions

1 vote
0 answers
103 views

Why is creating a uint8 more expensive than a uint256? [duplicate]

Assume a contract: contract A { function b() constant returns (uint8 result) { result =1; } } When I replace uint8 result with uint256 result then the creation of the contract gets ...
Roland Kofler's user avatar
13 votes
3 answers
17k views

What uint type should be declared for unix timestamps?

I try to specify uint type to uint16 instead of just doing uint or uint256 when dealing with time stamps but it says that I must use at least uint24. It works with uint24, but shouldn't uint16 be ...
NowsyMe's user avatar
  • 1,375
11 votes
1 answer
13k views

Testing Error thrown with hardhat

How would you test the following function with solidity v0.7 and hardhat v2.3.3? function myFunction(int8 _num) public { require(_num > 5, "Num should be bigger than 5"); ....
ntonnelier's user avatar
8 votes
3 answers
5k views

Type casting msg.value to uint248

I am new to solidity programming and sorry if my question is very basic. I am wondering if we can cast msg.value to uint248 Example below ; uint value; value = (uint248) (msg.value);
Deepa's user avatar
  • 241
4 votes
2 answers
3k views

Initialize a fixed size, 2 dimensional array within function

In Solidity, how do I define a fixed size, 2 dimensional uint8 array scoped to a function, initialized with all zeros? E.g. func(){ var myArr = new uint8[5][5](); // which does not work. }
Jasper's user avatar
  • 213
4 votes
1 answer
1k views

Why time values should be used as uint256?

Is there a reason to use the time value as uint256? Is not uint128 enough? UnixTime...
Tom's user avatar
  • 75
7 votes
2 answers
2k views

Use uint40 for time in Solidity?

My question is: Should I use uint40 for time in Solidity? All the examples I've seen use uint256 for time, however, I think it's too wasteful -- while using uint32 is maybe a little aggressive due to ...
Jerry Ji's user avatar
  • 371
2 votes
1 answer
863 views

Is it better practice to use smaller uint sizes when applicable?

My understanding of uint sizes is that smaller sizes will decrease gas costs. In my current dapp I'm building, I am dealing with time, for which it seems that uint32 will be plenty for my purposes (...
quantummidget's user avatar
3 votes
2 answers
182 views

Are storage variables tightly packed like struct fields?

Tight variable packing is a known coding pattern in Solidity for saving gas by placing struct fields that are lower than 256 bits closer to one another. Does this logic apply to storage variables? ...
Paul Razvan Berg's user avatar
0 votes
1 answer
295 views

Why does Uniswap use Q notation versus the uint256 ratio price?

Question: Why does Uniswap use Q notation versus the uint256 ratio price? A price in uniswap is always in token1/token0. Which token is which depends on the hex value assigned by the contract address ...
Nat's user avatar
  • 299
1 vote
0 answers
79 views

Store constants as non-256 bit fields

My contract has a lot of uint256 constant fields that are later used for various calculations. I am close to reaching the maximum allowed contract size and I am looking for optimizations. I see that ...
omnomnom's user avatar
  • 177