Skip to content
On this page

hashMessage โ€‹

Calculates an Ethereum-specific hash in EIP-191 format: keccak256("\x19Ethereum Signed Message:\n" + len(message) + message)).

Import โ€‹

ts
import { hashMessage } from 'viem'

Usage โ€‹

ts
import { hashMessage } from 'viem'

hashMessage('hello world') 
// 0xd9eba16ed0ecae432b71fe008c98cc872bb4cc214d3220a36f365326cf807d68

// Hash a hex data value.  
hashMessage({ raw: '0x68656c6c6f20776f726c64' })
// 0xd9eba16ed0ecae432b71fe008c98cc872bb4cc214d3220a36f365326cf807d68

// Hash a bytes data value.  
hashMessage({ 
  raw: Uint8Array.from([
    104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100,
  ])})
// 0xd9eba16ed0ecae432b71fe008c98cc872bb4cc214d3220a36f365326cf807d68

Returns โ€‹

Hex

The hashed message.

Parameters โ€‹

message โ€‹

Message to hash.

  • Type: string | { raw: Hex | ByteArray }

Released under the MIT License.