What is keccak256
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)) ==
keccak256(abi.encodePacked(anotherVariable));
Spotted a typo or have a suggestion to make this crypto dev article better? Please let me know!
Previous post
๐ Solidity Auditing online quiz
Learn how to audit smart contracts by looking at some example code and trying to find the bugs
โฝ Solidity Gas Optimizations Guide
How to optimize and reduce gas usage in your smart contracts in Solidity
๐งช Guide to testing with Foundry
Guide to adding testing for your Solidity contracts, using the Foundry and Forge tools
๐ Guide to UTXO
UTXO and the UTXO set (used by blockchains such as Bitcoin) explained
๐ Solidity Assembly Guide
Introduction guide to using assembly in your Solidity smart contracts
๐ฆ Ethereum EOF format explained
Information explaining what the upcoming Ethereum EOF format is all about