Skip to content

Keccak256 and Function Selector

Hash any text or hex with keccak256, or paste a signature like transfer(address,uint256) to get its 4-byte selector and event topic. Everything runs in your browser.

EthereumBaseBNB Smart ChainPolygonno signup · no wallet connect · free

Canonical form without parameter names, for example Transfer(address,address,uint256).

Selector and topic

Function selector
0xa9059cbb
Event topic
0xa9059cbb2ab09eb219583f4a59a5d0623ade346d962bcd4e46b11da047c9049b

keccak256

Hash
0x1c8aff950685c2ed4bc3174f3472287b56d9517b9c948127319a09a7a36deac8

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

  1. Write the canonical signature: the function name and parameter types, with no names and no spaces, like transfer(address,uint256).
  2. Hash the signature string with keccak256.
  3. The first four bytes of the hash are the function selector, 0xa9059cbb in 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.

Decode and format onchain data automatically

The evmquery API resolves ABIs and formats units with formatUnits in the expression. No monthly cap on the free tier.