Hashing and selectors without leaving the browser
Keccak256 is the hash function behind Ethereum function selectors, event topics, storage slots, and address checksums. This tool hashes text or hex and derives the selector and topic for any Solidity signature.
Key facts
- Hash UTF-8 text or raw hex bytes with keccak256.
- Get the 4-byte function selector and the 32-byte event topic from one signature.
- Runs in your browser. Nothing is sent to a server.
- Uses Ethereum’s Keccak256, which is not the same as NIST SHA-3.
How a selector is built
- Write the canonical signature: the function name and parameter types, with no names and no spaces, like
transfer(address,uint256). - Hash the signature string with keccak256.
- The first four bytes of the hash are the function selector,
0xa9059cbbin this case.
The same hash used in full is the event topic. Events put it in topic 0 of each log, so Transfer(address,address,uint256) hashes to 0xddf252ad... and you filter ERC-20 transfer logs by it.
Common selectors:
| Signature | Selector |
|---|---|
transfer(address,uint256) |
0xa9059cbb |
approve(address,uint256) |
0x095ea7b3 |
balanceOf(address) |
0x70a08231 |
In code
import { keccak256, stringToHex, toFunctionSelector } from "viem";
keccak256(stringToHex("hello"));toFunctionSelector("function transfer(address,uint256)"); // "0xa9059cbb"A selector only names a function, and you cannot invert it. If you hold raw calldata and want the function and arguments, the Calldata Decoder resolves the ABI from the contract address and decodes it, with no signature guessing. To check which methods a contract exposes, use the Contract Inspector.
FAQ
What is a function selector?
The first four bytes of the keccak256 hash of a function’s canonical signature. It is the first four bytes of transaction calldata and tells the contract which function to run. For transfer(address,uint256) it is 0xa9059cbb.
What is an event topic?
The full 32-byte keccak256 hash of an event signature. It is stored as topic 0 of every log the event emits, so you filter logs by it.
Is Ethereum’s keccak256 the same as SHA-3?
No. Ethereum uses the original Keccak submission, which differs from the final NIST SHA-3 standard in its padding. The two produce different digests for the same input.
Why is the signature rejected?
Use the form name(type,type) with Solidity ABI types such as address, uint256, bytes32, or tuple types in parentheses. Write uint256 rather than the alias uint, and leave out spaces between types.
Can I reverse a selector back to a function name?
No, a hash cannot be inverted. Signature databases such as 4byte guess candidates, but they can collide. Resolving the contract’s ABI from its address is the reliable route, which the Calldata Decoder does.
Does this send my input anywhere?
No. Hashing runs in your browser with no network request.
Related
- Calldata Decoder: decode raw calldata using the ABI resolved from an address
- Contract Inspector: the full method list of a contract
- Ethereum Unit Converter: convert wei, gwei, and ether