A Smart Contract needs to check the uniqueness of a number inside a serie. The serie is specified by a string, and the number by a uint256 type. Is there any easy way on Solidity to compute a hash from these two mixed parameters?
This hash will be very handy to identify uniquely the corresponding items, better than using the string and the number. What will be the best type for the resulting hash? A string or a bytes32? Thx!
Best Answer
Another correction (2019-05-17): In modern Solidity version you can no longer pass multiple arguments to
keccak256
. It now only takes one argument of typebytes
. You can still hash multiple values together like this:Correction thanks to @Ismael: The easiest and cheapest way is just to pass multiple arguments to the hashing function:I think the easiest way is to take the hash of theuint256
, then take the hash of thestring
and thenxor
them together:Hashes are usually stored inbytes32
, not in astring
, becausestring
's cost more gas and the hashing functions return abytes32
anyways.