New to blockchain software development? Read my beginners guide here

What is keccak256

Created on August 2022 โ€ข Tags: solidityethereumguides

A guide on keccak256 hash function

Table of Contents for What is keccak256

Intro - what is Keccak256 and why is it used in Solidity

keccak256 is a very commonly used hash function in the Solidity programming language. It returns a bytes32 value.

It is based on SHA-3 (although is not technically the exact same).

Note: if you use the web3 JS libraryโ€™s web3.utils.soliditySha3() function, you might be surprised to learn you are actually running keccak256, and not SHA3.

How to compare values with keccak256

You can pass in any number of arguments to keccak256. It is often used to check if two values are equal (by passing in values from abi.encodePacked(...)).

You can check if two values are the same but comparing the keccak256 value of them. For example:

isTheSame = keccak256(abi.encodePacked(someVariable)) == 

Spotted a typo or have a suggestion to make this crypto dev article better? Please let me know!

See all posts (70+ more)

See all posts (70+ more)

Was this post helpful? ๐Ÿ“ง

If you liked this content and want to receive emails about future posts like this, enter your email. I'll never spam you.

Or follow me on @CryptoGuide_Dev on twitter

By using this site, you agree that you have read and understand its Privacy Policy and Terms of Use.
Use any information on this site at your own risk, I take no responsibility for the accuracy of safety of the information on this site.