EIP-712 Message Hasher

Calculate EIP-712 hashes for typed structured data signing


1. What is EIP-712?

EIP-712 is a standard for hashing and signing typed structured data. It provides a way to sign data that is human-readable and secure, commonly used for permit signatures, meta-transactions, and DAO voting.

2. How does it work?

EIP-712 hashing involves three steps:

  1. Calculate the domain separator hash
  2. Calculate the message struct hash
  3. Combine them: keccak256("\x19\x01" + domainSeparator + messageHash)

The domain separator includes information about the dApp, version, chain ID, and verifying contract to prevent signature replay across different contexts.

3. Examples

ERC-20 Permit

Primary Type: "Permit"
Domain: {"name":"USDC","version":"1","chainId":1,"verifyingContract":"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"}
Types: {"Permit":[{"name":"owner","type":"address"},{"name":"spender","type":"address"},{"name":"value","type":"uint256"},{"name":"nonce","type":"uint256"},{"name":"deadline","type":"uint256"}]}
Message: {"owner":"0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045","spender":"0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D","value":"1000000","nonce":"0","deadline":"1735689600"}

Meta-transaction

Primary Type: "ForwardRequest"
Domain: {"name":"MinimalForwarder","version":"1","chainId":137}
Types: {"ForwardRequest":[{"name":"from","type":"address"},{"name":"to","type":"address"},{"name":"value","type":"uint256"},{"name":"gas","type":"uint256"},{"name":"nonce","type":"uint256"},{"name":"data","type":"bytes"}]}
Message: {"from":"0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045","to":"0x1234567890123456789012345678901234567890","value":"0","gas":"100000","nonce":"0","data":"0x"}

NFT Order (OpenSea-style)

Primary Type: "Order"
Domain: {"name":"Seaport","version":"1.0","chainId":1}
Types: {"Order":[{"name":"maker","type":"address"},{"name":"taker","type":"address"},{"name":"price","type":"uint256"},{"name":"tokenId","type":"uint256"}]}
Message: {"maker":"0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045","taker":"0x0000000000000000000000000000000000000000","price":"1000000000000000000","tokenId":"42"}

References