hashMessage
Calculates an Ethereum-specific hash in EIP-191 format: keccak256("\x19Ethereum Signed Message:\n" + len(message) + message))
.
Import
import { hashMessage } from 'viem'
Usage
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
The hashed message.
Parameters
message
Message to hash.
-
Type:
string | { raw: Hex | ByteArray }