Skip to main content
Hash a UTF-8 string using SHA-256 cryptographic hash function
import { SHA256 } from '@tevm/voltaire/SHA256';
import { Hex } from '@tevm/voltaire/Hex';

// Hash a simple string
const message = "Hello, World!";
const hash = SHA256.hash(new TextEncoder().encode(message));
const hexHash = Hex.fromBytes(hash);

// Hash another string
const hash2 = SHA256.hash(new TextEncoder().encode("Voltaire"));
const hexHash2 = Hex.fromBytes(hash2);
This is a fully executable example. View the complete source with test assertions at examples/hashing/sha256-hash.ts.