Skip to main content
Hash a UTF-8 string using Keccak256 and get the result as hex
import { Keccak256 } from '@tevm/voltaire/crypto/Keccak256';
import * as Hex from '@tevm/voltaire/primitives/Hex';

// Hash a simple string
const message = 'Hello, World!';
const hash = Keccak256.hashString(message);
const hexHash = Hex.fromBytes(hash);
console.log('Keccak256 hash:', hexHash);

// Hash an empty string
const emptyHash = Keccak256.hashString('');
const emptyHexHash = Hex.fromBytes(emptyHash);
console.log('Empty string hash:', emptyHexHash);

// Hash is always 32 bytes (256 bits)
console.log('Hash length:', hash.length, 'bytes');
This is a fully executable example. View the complete source with test assertions at examples/hashing/keccak256-string.ts.