keccak256

Computes the Keccak-256 hash used by the EVM, returning a BYTES32 digest. Non-0x VARCHAR input is hashed as UTF-8, 0x-prefixed VARCHAR input is decoded to bytes first, and multi-argument overloads hash the exact unframed concatenation in argument order.

Example

Local

1
-- Derive the ERC-20 Transfer event topic from its canonical signature
2
SELECT keccak256('Transfer(address,address,uint256)')::VARCHAR AS topic0;
3
-- => [{"topic0":"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"}]
Notebook ready in readonly mode.

API reference

Exact signatures with descriptions, requirements, inputs, returns, and examples.

keccak256(VARCHAR) #

Accepts UTF-8 literals or 0x-prefixed hex strings. A VARCHAR beginning with 0x is decoded as hex bytes before hashing; use the BLOB overload when you need exact binary hashing.

Inputs

Name Type Use
input VARCHAR

Non-0x VARCHAR values are hashed as UTF-8 bytes. 0x-prefixed VARCHAR values are decoded as hex bytes before hashing.

required positional

Returns

Name Type
hash BYTES32

Keccak-256 digest. Returns the 32-byte EVM hash as BYTES32.

Guidance

Text, hex, and EVM words

keccak256 accepts both text-oriented and binary-oriented overloads. A VARCHAR beginning with 0x is treated as hex bytes, while other VARCHAR input is hashed as UTF-8.

  • Use keccak256('hello') for UTF-8 text.
  • Use keccak256('0x68656c6c6f') for hex encoded bytes.
  • Use keccak256(blob_value) when the bytes are already binary.
  • Do not use the VARCHAR overload when a 0x-prefixed string must be hashed as literal text.
  • Use explicit ADDRESS::BYTES32 and UINT256 casts when computing Solidity mapping slots.

Local SQL

1
SELECT
2
keccak256('hello') AS utf8_hash,
3
keccak256('0x68656c6c6f') AS hex_hash,
4
keccak256('0x68656c6c6f'::BLOB) AS blob_hash;
Notebook ready in readonly mode.

Local SQL

1
SELECT keccak256(
2
'0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045'::ADDRESS::BYTES32,
3
3::UINT256
4
) AS mapping_slot;
Notebook ready in readonly mode.

String and binary inputs

The VARCHAR overload treats 0x-prefixed strings as hex bytes before hashing. Non-0x VARCHAR inputs are hashed as UTF-8 bytes. Use the BLOB overload for exact binary hashing.

Additional overloads

keccak256(BLOB) #

Hashes a single BLOB (ADDRESS, BYTES32, or raw binary) exactly as it is stored.

Inputs

Name Type Use
data BLOB

BLOB, ADDRESS, or BYTES32 bytes to hash exactly as stored.

required positional

Returns

Name Type
hash BYTES32

Keccak-256 digest. Returns the 32-byte EVM hash as BYTES32.

Show 6 more overloads
keccak256(BLOB, BLOB) #

Concatenates two binary values without length delimiters before hashing, mirroring keccak256(abi.encodePacked(a, b)) for already-encoded byte segments.

Inputs

Name Type Use
left BLOB

First BLOB segment in the concatenation.

required positional
right BLOB

Second BLOB segment in the concatenation.

required positional

Returns

Name Type
hash BYTES32

Keccak-256 digest. Returns keccak256(left || right) as BYTES32.

keccak256(BYTES32, BYTES32) #

Concatenates two EVM word inputs before hashing. Use this for Solidity mapping slots such as keccak256(owner::BYTES32, slot::UINT256).

Inputs

Name Type Use
left BYTES32

First 32-byte ABI-style word in the concatenation.

required positional
right BYTES32

Second 32-byte ABI-style word in the concatenation.

required positional

Returns

Name Type
hash BYTES32

Keccak-256 digest. Returns keccak256(left || right) as BYTES32.

keccak256(BYTES32, UINT256) #

Concatenates two EVM word inputs before hashing. Use this for Solidity mapping slots such as keccak256(owner::BYTES32, slot::UINT256).

Inputs

Name Type Use
left BYTES32

First 32-byte ABI-style word in the concatenation.

required positional
right UINT256

Second 32-byte ABI-style word in the concatenation.

required positional

Returns

Name Type
hash BYTES32

Keccak-256 digest. Returns keccak256(left || right) as BYTES32.

keccak256(UINT256, BYTES32) #

Concatenates two EVM word inputs before hashing. Use this for Solidity mapping slots such as keccak256(owner::BYTES32, slot::UINT256).

Inputs

Name Type Use
left UINT256

First 32-byte ABI-style word in the concatenation.

required positional
right BYTES32

Second 32-byte ABI-style word in the concatenation.

required positional

Returns

Name Type
hash BYTES32

Keccak-256 digest. Returns keccak256(left || right) as BYTES32.

keccak256(UINT256, UINT256) #

Concatenates two EVM word inputs before hashing. Use this for Solidity mapping slots such as keccak256(owner::BYTES32, slot::UINT256).

Inputs

Name Type Use
left UINT256

First 32-byte ABI-style word in the concatenation.

required positional
right UINT256

Second 32-byte ABI-style word in the concatenation.

required positional

Returns

Name Type
hash BYTES32

Keccak-256 digest. Returns keccak256(left || right) as BYTES32.

keccak256(BLOB, BLOB, BLOB) #

Hashes three BLOB inputs as the unframed concatenation a || b || c. Callers must supply unambiguous framing when segment boundaries matter.

Inputs

Name Type Use
a BLOB

First BLOB segment in the concatenation.

required positional
b BLOB

Second BLOB segment in the concatenation.

required positional
c BLOB

Third BLOB segment in the concatenation.

required positional

Returns

Name Type
hash BYTES32

Keccak-256 digest. Returns keccak256(a || b || c) as BYTES32.

Examples

Local SQL

1
-- A 0x VARCHAR is decoded before hashing; plain text is UTF-8
2
SELECT
3
keccak256('0x68656c6c6f')::VARCHAR AS hex_bytes_hash,
4
keccak256('hello')::VARCHAR AS utf8_hash;
5
-- => [{"hex_bytes_hash":"0x1c8aff950685c2ed4bc3174f3472287b56d9517b9c948127319a09a7a36deac8","utf8_hash":"0x1c8aff950685c2ed4bc3174f3472287b56d9517b9c948127319a09a7a36deac8"}]
Notebook ready in readonly mode.

Local SQL

1
-- Derive a Solidity mapping slot from a padded owner word and slot number
2
SELECT keccak256(
3
'0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045'::ADDRESS::BYTES32,
4
3::UINT256
5
)::VARCHAR AS mapping_slot;
6
-- => [{"mapping_slot":"0x3a988d762a24303c37d08f1543db6143453b579691d5c20fed39629ff1334cca"}]
Notebook ready in readonly mode.

Related functions

Category and tags

Category
EVM utilities
Tag
Keccak