UserOperation Hash

Learn the foundational concepts of how a ERC-4337 UserOperation is signed and how a UserOpHash can be generated in Solidity, JS, and Go.

The ERC-4337 standard is un-opinionated in terms of how the signature field is encoded and is up to the contract to decide how to validate it. However there are certain practices that should be followed.


Want an example?

This guide touches on some foundational concepts related to smart contract accounts.

If you're after more concrete examples, check out

The userOpHash

The userOpHash is a keccak256 hash of three things in order:

  1. The entire User Operation (minus the signature field).
  2. The EntryPoint address.
  3. The chain ID.

All signatures should be a signed message of the userOpHash. To optimize gas, the EntryPoint will generate this hash once and pass it to both validateUserOp and validatePaymasterUserOp during the verification phase.

How do I get the userOpHash for X language?

There are currently a few examples in various languages for generating a userOpHash. Refer to the list below for reference to specific implementations.

It is important that a userOpHash generated off-chain matches the one generated on-chain by the EntryPoint. A mismatched hash will result in incorrect validation and subsequently rejected by the bundler.