1

I have questions about how many bytes each type might be.

Question 1) now() timestamp. i think it's uint which means uint256 which means 32 bytes? Am I right?

Question 2) what does bytes32 mean? They say it's an array. but i can't do push on it. something like this: bytes32 public array; array.push("good"); so it's kind of an array like a string? string s = "good"; like this? but imagine what if I want to have arrays of 32 bytes?

Question 3) what about event logs topics? if I write uint indexed var1 in a log, a) i know that it's gonna cost me 32 bytes as uint is 32 bytes but what if b) I write bytes16 indexed var2 , is it still gonna cost me 32 bytes or just 16 bytes? and c) what if i save more than 32 bytes in a log and it's a topic, lets say 50bytes, is it gonna cost me still 32 bytes and keccak256 hash will be stored there ? Am I right in a) , b) and c)

Thanks guys. before writing questions, I always try to put my idea on it .

1 Answer 1

1

Question 1) now() timestamp. i think it's uint which means uint256 which means 32 bytes? Am I right?

Yes, that is correct.

Question 2) what does bytes32 mean? They say it's an array. but i can't do push on it. something like this: bytes32 public array; array.push("good"); so it's kind of an array like a string? string s = "good"; like this? but imagine what if I want to have arrays of 32 bytes?

bytes32 is just a 256 bit word. It's size is fixed, just like for example uint256. If you want a dynamically sized byte array, use the bytes array type

Question 3) what about event logs topics? if I write uint indexed var1 in a log, a) i know that it's gonna cost me 32 bytes as uint is 32 bytes but what if b) I write bytes16 indexed var2 , is it still gonna cost me 32 bytes or just 16 bytes? and c) what if i save more than 32 bytes in a log and it's a topic, lets say 50bytes, is it gonna cost me still 32 bytes and keccak256 hash will be stored there ? Am I right in a) , b) and c)

This is not very well documented. My advice is to test somehow it and possibly post the results here.

The yellow paper states that the logs can contain any amount of data on page 5 just before equation 24:

A log entry is a tuple of the logger’s address possibly empty series of 32-byte log topics, and some number of bytes of data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.