Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cryptozombies why use keccak in comparing

Tags:

ethereum

I am already in lesson 2 Chapter 13 of cryptozombies tutorial. In feedAndMultiply function why they use keccak to compare Kitty rather the exact character.

if (keccak256(_species) == keccak256("kitty"))   

why not

if (_species == "kitty") ?
like image 340
roytags Avatar asked Jan 02 '26 00:01

roytags


1 Answers

The == operator is only supported for booleans, integers, fixed point numbers (once support for fixed point numbers is launched), addresses, and static byte arrays. Solidity does not support == for dynamic arrays (which string is). To work around this, they are simply taking the hash value of the two strings and then comparing the result.

The Types page in the Solidity docs outlines all of the supported operations for each type.

like image 197
Adam Kipnis Avatar answered Jan 06 '26 11:01

Adam Kipnis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!