Finance & Economics / Blockchain & Crypto

Keccak-256 Hash Calculator

Keccak-256 Hash Function

What is Keccak-256?

Keccak-256 is the hash function used by Ethereum. It's based on the SHA-3 standard but differs from the finalized SHA-3 specification. Ethereum uses the original Keccak algorithm that was submitted to the NIST competition.

⚠️ Keccak vs SHA-3:

Keccak-256 (used by Ethereum) ≠ SHA3-256 (NIST standard). They produce different outputs! Ethereum uses the original Keccak before NIST made changes.

Ethereum Use Cases:

  • Address Generation: Public key → Keccak-256 → address
  • Function Signatures: First 4 bytes of Keccak hash
  • Event Topics: Event signature hashing
  • Storage Keys: Mapping key hashing
  • Transaction Hashes: Unique transaction identifiers

Example: Ethereum Address Generation

1. Public Key: 04abc123...def789 (65 bytes)

2. Keccak-256 Hash: c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470

3. Take last 20 bytes: 0x...ad8045d85a470

4. Add 0x prefix: 0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb

Example: Function Selector

Function: transfer(address,uint256)

Keccak-256: a9059cbb2ab09eb219583f4a59a5d0623ade346d962bcd4e46b11da047c9049b

First 4 bytes: 0xa9059cbb

This becomes the function selector in the transaction data

How to Calculate (JavaScript):

// Using ethers.js
import { keccak256, toUtf8Bytes } from 'ethers';
const hash = keccak256(toUtf8Bytes('Hello'));

// Using keccak package
import { keccak256 } from 'keccak';
const hash = keccak256(Buffer.from('Hello')).toString('hex');

💡 Key Differences from SHA-256:

  • Ethereum uses Keccak-256 (not SHA3-256)
  • Bitcoin uses SHA-256 (different algorithm)
  • Keccak was selected as SHA-3 winner in 2012
  • NIST made changes before standardizing as SHA-3 in 2015
  • Ethereum had already adopted original Keccak by then
  • Both produce 256-bit (64 hex character) hashes

🔧 Implementation Note:

True Keccak-256 calculation requires a specialized library. This calculator demonstrates the concept. For production use, install packages like:

  • ethers.js or viem (for Ethereum development)
  • keccak or js-sha3 (standalone hashing)