---
eip: 712
label: EIP-712
title: Typed structured data hashing and signing
status: Final
type: Standards Track
category: Interface
created: 2017-09-12
requires: 155, 191
official: https://eips.ethereum.org/EIPS/eip-712
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-712.md
canonical: https://eips.huatuo.xyz/eip-712/
lang: en
tldr: A standard way to hash and sign typed, structured data, so wallets can show users readable fields instead of a hex blob and contracts can verify the signature cheaply.
tags: [signatures, wallet, offchain, permit, interface]
---

# EIP-712: Typed structured data hashing and signing

> A procedure for hashing and signing of typed structured data as opposed to just bytestrings.

**TL;DR:** A standard way to hash and sign typed, structured data, so wallets can show users readable fields instead of a hex blob and contracts can verify the signature cheaply.

## What problem does it solve?

Off-chain signatures save gas. You sign a message, and someone else submits it to a contract later. Gasless approvals, order books and meta-transactions all depend on this. But with plain `eth_sign`, a user only sees an opaque hex string and has no idea what they are authorizing. Each app also hashed its data in its own ad-hoc way, which is easy to get wrong.

EIP-712 defines one peer-reviewed encoding for structured data. Wallets can display the fields ("Permit: spender X, value 100, deadline …"), and signatures from one app or chain cannot be reused in another.

## How it works

The final digest to sign is:

```
keccak256("\x19\x01" ‖ domainSeparator ‖ hashStruct(message))
```

The `0x19 0x01` prefix follows [ERC-191](/eip-191/) and can never be mistaken for an RLP transaction.

- **`hashStruct(s) = keccak256(typeHash ‖ encodeData(s))`**
- **`typeHash`** is `keccak256` of the type string, for example `Mail(address from,address to,string contents)`. Referenced struct types are appended, sorted by name.
- **`encodeData`** encodes each member as 32 bytes. Atomic types are ABI-style. `string` and `bytes` are hashed. Arrays are hashed. Nested structs are encoded with their own `hashStruct`.
- **`domainSeparator`** is the `hashStruct` of an `EIP712Domain` with any of these fields: `name`, `version`, `chainId` ([EIP-155](/eip-155/)), `verifyingContract`, `salt`. It ties the signature to one app, version, chain and contract.

The RPC method is `eth_signTypedData`, which takes `{ types, primaryType, domain, message }`.

## Sample code

Signing and verifying with ethers v6:

```ts
import { Wallet, verifyTypedData } from "ethers";

const wallet = Wallet.createRandom();

const domain = {
  name: "Ether Mail",
  version: "1",
  chainId: 1,
  verifyingContract: "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC",
};
const types = {
  Person: [{ name: "name", type: "string" }, { name: "wallet", type: "address" }],
  Mail: [
    { name: "from", type: "Person" },
    { name: "to", type: "Person" },
    { name: "contents", type: "string" },
  ],
};
const message = {
  from: { name: "Cow", wallet: "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826" },
  to: { name: "Bob", wallet: "0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB" },
  contents: "Hello, Bob!",
};

const sig = await wallet.signTypedData(domain, types, message);
console.log(verifyTypedData(domain, types, message, sig) === wallet.address); // true
```

On-chain, Solidity computes the same digest:

```solidity
bytes32 constant MAIL_TYPEHASH = keccak256("Mail(Person from,Person to,string contents)Person(string name,address wallet)");
bytes32 digest = keccak256(abi.encodePacked("\x19\x01", DOMAIN_SEPARATOR, structHash));
address signer = ecrecover(digest, v, r, s);
```

## Things to know

- **No replay protection is built in.** Include a nonce and a deadline in your struct, and mark them used on-chain.
- Wallets commonly expose this as `eth_signTypedData_v4`. Earlier "v1/v3" variants differ in how they handle arrays and nested structs.
- Well-known users include [ERC-2612](/eip-2612/) `permit` and many DEX order formats. Smart-contract wallets verify these signatures with [ERC-1271](/eip-1271/). [ERC-5267](/eip-5267/) lets a contract publish its domain.
- Typed-data signatures are a favorite phishing vector, because one signed `Permit` can drain a token. Always read what you sign.
- Use an audited helper (OpenZeppelin `EIP712`) rather than hand-rolling the encoding. This EIP is Final.


---

This is an unofficial plain-language summary. Read the full specification: https://eips.ethereum.org/EIPS/eip-712
