Skip to content

Hash.keccak256

Calculates the Keccak256 hash of a Bytes.Bytes or Hex.Hex value.

This function is a re-export of keccak_256 from @noble/hashes, an audited & minimal JS hashing library.

Imports

Named
import { Hash } from 'ox'

Examples

import { Hash } from 'ox'
 
Hash.keccak256('0xdeadbeef')
'0xd4fd4e189132273036449fc9e11198c739161b4c0116a9a2dccdfa1c492006f1'

Calculate Hash of a String

import { Hash, Hex } from 'ox'
 
Hash.keccak256(Hex.fromString('hello world'))
'0x3ea2f1d0abf3fc66cf29eebb70cbd4e7fe762ef8a09bcc06c8edf641230afec0'

Configure Return Type

import { Hash } from 'ox'
 
Hash.keccak256('0xdeadbeef', { as: 'Bytes' })
Uint8Array [...]

Definition

function keccak256<value, as>(
  value: value | Hex.Hex | Bytes.Bytes,
  options?: keccak256.Options<as>,
): keccak256.ReturnType<as>

Source: src/core/Hash.ts

Parameters

value

  • Type: value | Hex.Hex | Bytes.Bytes

Bytes.Bytes or Hex.Hex value.

options

  • Type: keccak256.Options<as>
  • Optional

Options.

options.as

  • Type: "Bytes" | "Hex" | as
  • Optional

The return type.

Return Type

Keccak256 hash.

keccak256.ReturnType<as>