> **Can't find what you're looking for?** Use `search_docs` on the docs MCP server at `https://v3.viem.sh/api/mcp` to find what you need.

# TypedData

:::info
`TypedData` is a re-export of ox's [`TypedData`](https://oxlib.sh/api/TypedData). Refer to the ox documentation for the full reference.
:::

Utility functions for working with [EIP-712 Typed Data](https://eips.ethereum.org/EIPS/eip-712)

## Examples

### Getting Sign Payloads

Typed Data can be converted to a sign payload using [`TypedData.getSignPayload`](/docs/utilities/typeddata/getSignPayload):

```ts twoslash
// @noErrors
import { Secp256k1, TypedData, Hash } from 'viem/utils'

const payload = TypedData.getSignPayload({
  // [!code focus:99]
  domain: {
    name: 'Ether Mail',
    version: '1',
    chainId: 1,
    verifyingContract:
      '0x0000000000000000000000000000000000000000'
  },
  types: {
    Person: [
      { name: 'name', type: 'string' },
      { name: 'wallet', type: 'address' }
    ],
    Mail: [
      { name: 'from', type: 'Person' },
      { name: 'to', type: 'Person' },
      { name: 'contents', type: 'string' }
    ]
  },
  primaryType: 'Mail',
  message: {
    from: {
      name: 'Cow',
      wallet: '0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826'
    },
    to: {
      name: 'Bob',
      wallet: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB'
    },
    contents: 'Hello, Bob!'
  }
})

const signature = Secp256k1.sign({
  payload,
  privateKey: '0x...'
})
```

## Functions

| Name                | Description                         |
| ------------------- | ----------------------------------- |
| [`TypedData.assert`](/docs/utilities/typeddata/assert) | Asserts that [EIP-712 Typed Data](https://eips.ethereum.org/EIPS/eip-712) is valid. |
| [`TypedData.domainSeparator`](/docs/utilities/typeddata/domainSeparator) | Creates [EIP-712 Typed Data](https://eips.ethereum.org/EIPS/eip-712) [`domainSeparator`](https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator) for the provided domain. |
| [`TypedData.encode`](/docs/utilities/typeddata/encode) | Encodes typed data in [EIP-712 format](https://eips.ethereum.org/EIPS/eip-712): `0x19 ‖ 0x01 ‖ domainSeparator ‖ hashStruct(message)`. |
| [`TypedData.encodeType`](/docs/utilities/typeddata/encodeType) | Encodes [EIP-712 Typed Data](https://eips.ethereum.org/EIPS/eip-712) schema for the provided primaryType. |
| [`TypedData.extractEip712DomainTypes`](/docs/utilities/typeddata/extractEip712DomainTypes) | Gets [EIP-712 Typed Data](https://eips.ethereum.org/EIPS/eip-712) schema for EIP-721 domain. |
| [`TypedData.getSignPayload`](/docs/utilities/typeddata/getSignPayload) | Gets the payload to use for signing typed data in [EIP-712 format](https://eips.ethereum.org/EIPS/eip-712). |
| [`TypedData.hashDomain`](/docs/utilities/typeddata/hashDomain) | Hashes [EIP-712 Typed Data](https://eips.ethereum.org/EIPS/eip-712) domain. |
| [`TypedData.hashStruct`](/docs/utilities/typeddata/hashStruct) | Hashes [EIP-712 Typed Data](https://eips.ethereum.org/EIPS/eip-712) struct. |
| [`TypedData.serialize`](/docs/utilities/typeddata/serialize) | Serializes [EIP-712 Typed Data](https://eips.ethereum.org/EIPS/eip-712) schema into string. |
| [`TypedData.validate`](/docs/utilities/typeddata/validate) | Checks if [EIP-712 Typed Data](https://eips.ethereum.org/EIPS/eip-712) is valid. |

## Errors

| Name                | Description                         |
| ------------------- | ----------------------------------- |
| [`TypedData.BytesSizeMismatchError`](/docs/utilities/typeddata/errors#typeddatabytessizemismatcherror) | Thrown when the bytes size of a typed data value does not match the expected size. |
| [`TypedData.InvalidArrayError`](/docs/utilities/typeddata/errors#typeddatainvalidarrayerror) | Thrown when an array-typed value is not an array. |
| [`TypedData.InvalidArrayLengthError`](/docs/utilities/typeddata/errors#typeddatainvalidarraylengtherror) | Thrown when a fixed-length array does not match its declared length. |
| [`TypedData.InvalidDomainError`](/docs/utilities/typeddata/errors#typeddatainvaliddomainerror) | Thrown when the domain is invalid. |
| [`TypedData.InvalidPrimaryTypeError`](/docs/utilities/typeddata/errors#typeddatainvalidprimarytypeerror) | Thrown when the primary type of a typed data value is invalid. |
| [`TypedData.InvalidStructTypeError`](/docs/utilities/typeddata/errors#typeddatainvalidstructtypeerror) | Thrown when the struct type is not a valid type. |

## Types

| Name                | Description                         |
| ------------------- | ----------------------------------- |
| [`TypedData.Definition`](/docs/utilities/typeddata/types#typeddatadefinition) |  |
| [`TypedData.Domain`](/docs/utilities/typeddata/types#typeddatadomain) |  |
| [`TypedData.EIP712DomainDefinition`](/docs/utilities/typeddata/types#typeddataeip712domaindefinition) |  |
| [`TypedData.MessageDefinition`](/docs/utilities/typeddata/types#typeddatamessagedefinition) |  |
| [`TypedData.Parameter`](/docs/utilities/typeddata/types#typeddataparameter) |  |
| [`TypedData.TypedData`](/docs/utilities/typeddata/types#typeddatatypeddata) |  |

## Viem Helpers

Functions added by Viem on top of the `TypedData` module.

| Name | Description |
| ---- | ----------- |
| [`TypedData.recoverAddress`](/docs/utilities/typeddata/recoverAddress) | Recovers the signing address of signed [EIP-712](https://eips.ethereum.org/EIPS/eip-712) typed data. |
| [`TypedData.verify`](/docs/utilities/typeddata/verify) | Verifies that signed [EIP-712](https://eips.ethereum.org/EIPS/eip-712) typed data was signed by the provided address (or public key). |
