Skip to main content

hashMessage

Callable

  • hashMessage(message: string, skipPrefix?: boolean): string

  • Hashes the given message. The data will be UTF-8 HEX decoded and enveloped as follows: "\x19Ethereum Signed Message:\n" + message.length + message and hashed using keccak256.


    Parameters

    • message: string

      A message to hash, if its HEX it will be UTF8 decoded.

    • skipPrefix: boolean = false

      (default: false) If true, the message will be not prefixed with "\x19Ethereum Signed Message:\n" + message.length

    Returns string

    The hashed message

    web3.eth.accounts.hashMessage("Hello world")

    > "0x8144a6fa26be252b86456491fbcd43c1de7e022241845ffea1c3df066f7cfede"

    web3.eth.accounts.hashMessage(web3.utils.utf8ToHex("Hello world")) // Will be hex decoded in hashMessage

    > "0x8144a6fa26be252b86456491fbcd43c1de7e022241845ffea1c3df066f7cfede"

    web3.eth.accounts.hashMessage("Hello world", true)

    > "0xed6c11b0b5b808960df26f5bfc471d04c1995b0ffd2055925ad1be28d6baadfd"