> **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.

# Get EIP-712 Domain \[contract.getEip712Domain]

Reads the EIP-712 domain from a contract, based on the [ERC-5267](https://eips.ethereum.org/EIPS/eip-5267) specification.

## Usage

This example reads the EIP-712 domain from a contract, based on the [ERC-5267](https://eips.ethereum.org/EIPS/eip-5267) specification.

:::code-group
```ts twoslash [example.ts]
import { client } from './viem.config'

const { domain, extensions, fields } = await client.contract.getEip712Domain({
  address: '0x57ba3ec8df619d4d243ce439551cce713bb17411',
})
// @log: {
// @log:   domain: {
// @log:     chainId: 1,
// @log:     name: 'ExampleContract',
// @log:     salt: '0x0000...0000',
// @log:     verifyingContract: '0x57bA3ec8DF619d4d243Ce439551cCE713bB17411',
// @log:     version: '1',
// @log:   },
// @log:   extensions: [],
// @log:   fields: '0x0f',
// @log: }
```

```ts twoslash [viem.config.ts] filename="viem.config.ts"
import { Client, http, publicActions } from 'viem'
import { mainnet } from 'viem/chains'

export const client = Client.create({
  chain: mainnet,
  transport: http(),
}).extend(publicActions())
```
:::

### Standalone Action

Call `Actions.contract.getEip712Domain` directly by passing the Client as the first argument.

:::code-group
```ts twoslash [example.ts]
import { Actions } from 'viem'
import { client } from './viem.config'

const { domain, extensions, fields } = await Actions.contract.getEip712Domain(client, {
  address: '0x57ba3ec8df619d4d243ce439551cce713bb17411',
})
// @log: {
// @log:   domain: {
// @log:     chainId: 1,
// @log:     name: 'ExampleContract',
// @log:     salt: '0x0000...0000',
// @log:     verifyingContract: '0x57bA3ec8DF619d4d243Ce439551cCE713bB17411',
// @log:     version: '1',
// @log:   },
// @log:   extensions: [],
// @log:   fields: '0x0f',
// @log: }
```

```ts twoslash [viem.config.ts] filename="viem.config.ts"
import { Client, http } from 'viem'
import { mainnet } from 'viem/chains'

export const client = Client.create({
  chain: mainnet,
  transport: http(),
})
```
:::

## Recipes

### Read a Counterfactual Domain

Pass the deployment factory and calldata when the contract has not been deployed.

```ts twoslash
import { Client, http, publicActions } from 'viem'
import { mainnet } from 'viem/chains'

const client = Client.create({
  chain: mainnet,
  transport: http(),
}).extend(publicActions())

const { domain } = await client.contract.getEip712Domain({
  address: '0x57ba3ec8df619d4d243ce439551cce713bb17411',
  factory: '0xE8Df82fA4E10e6A12a9Dab552bceA2acd26De9bb', // [!code focus]
  factoryData: '0xdeadbeef', // [!code focus]
})
```

### Inspect Optional Domain Metadata

Inspect `fields`, `salt`, and `extensions` when a contract advertises optional ERC-5267 metadata.

```ts twoslash
import { Client, http, publicActions } from 'viem'
import { mainnet } from 'viem/chains'

const client = Client.create({
  chain: mainnet,
  transport: http(),
}).extend(publicActions())

const {
  domain: { salt }, // [!code focus]
  extensions, // [!code focus]
  fields, // [!code focus]
} = await client.contract.getEip712Domain({
  address: '0x57ba3ec8df619d4d243ce439551cce713bb17411',
})
```

## Return Value

`{ domain, extensions, fields }`

The EIP-712 domain (with `chainId` as `number`), the ERC-5267 `extensions` (as `bigint[]`), and the `fields` bitmap (as `Hex`).

## Parameters

### address

* **Type:** `Address`

The address of the contract to read the EIP-712 domain from.

```ts twoslash
import { Actions, Client, http } from 'viem'
import { mainnet } from 'viem/chains'

const client = Client.create({ chain: mainnet, transport: http() })
// ---cut---
const domain = await Actions.contract.getEip712Domain(client, {
  address: '0x57ba3ec8df619d4d243ce439551cce713bb17411', // [!code focus]
})
```

### factory

* **Type:** `Address`

The address of the factory used to deploy the contract, for counterfactual (not-yet-deployed) reads.

```ts twoslash
import { Actions, Client, http } from 'viem'
import { mainnet } from 'viem/chains'

const client = Client.create({ chain: mainnet, transport: http() })
// ---cut---
const domain = await Actions.contract.getEip712Domain(client, {
  address: '0x57ba3ec8df619d4d243ce439551cce713bb17411',
  factory: '0xE8Df82fA4E10e6A12a9Dab552bceA2acd26De9bb', // [!code focus]
  factoryData: '0xdeadbeef', // [!code focus]
})
```

### factoryData

* **Type:** `Hex`

The calldata to execute on the `factory` to deploy the contract for a counterfactual read.

```ts twoslash
import { Actions, Client, http } from 'viem'
import { mainnet } from 'viem/chains'

const client = Client.create({ chain: mainnet, transport: http() })
// ---cut---
const domain = await Actions.contract.getEip712Domain(client, {
  address: '0x57ba3ec8df619d4d243ce439551cce713bb17411',
  factory: '0xE8Df82fA4E10e6A12a9Dab552bceA2acd26De9bb',
  factoryData: '0xdeadbeef', // [!code focus]
})
```

## Errors

| Error | Description |
| --- | --- |
| `Eip712Domain.NotFoundError` | The contract does not implement the ERC-5267 `eip712Domain()` function. |
