> ## Documentation Index
> Fetch the complete documentation index at: https://docs.qu.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# TypedDataEncoder

A **TypedDataEncode** prepares and encodes [EIP-712](https://eips.ethereum.org/EIPS/eip-712) payloads for signed
typed data.

This is useful for those that wish to compute various components of a typed data hash, primary types, or
sub-components, but generally the higher level [`Signer.signTypedData`](../classes/Signer#signTypedData) is more
useful.

## Constructors

### new TypedDataEncoder()

```ts theme={null}
new TypedDataEncoder(types): TypedDataEncoder
```

Create a new **TypedDataEncoder** for `types`.

This performs all necessary checking that types are valid and do not violate the
[EIP-712](https://eips.ethereum.org/EIPS/eip-712) structural constraints as well as computes the
[**primaryType**](/sdk/content/classes/TypedDataEncoder).

#### Parameters

| Parameter | Type                                                                               |
| :-------- | :--------------------------------------------------------------------------------- |
| `types`   | `Record`\<`string`, [`TypedDataField`](/sdk/content/interfaces/TypedDataField)\[]> |

#### Returns

[`TypedDataEncoder`](/sdk/content/classes/TypedDataEncoder)

#### Source

[hash/typed-data.ts:259](https://github.com/dominant-strategies/quais.js/blob/c1c12d43f9d34c6baad2b0542bd6d0acd6fefcbf/src/hash/typed-data.ts#L259)

## Properties

| Property      | Modifier   | Type     | Description                                                                                                                                                                                                                                                                                                                                                                 |
| :------------ | :--------- | :------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `primaryType` | `readonly` | `string` | The primary type for the structured [**types**](/sdk/content/classes/TypedDataEncoder#types).<br /><br />This is derived automatically from the [**types**](/sdk/content/classes/TypedDataEncoder#types), since no recursion is possible, once the DAG for<br />the types is consturcted internally, the primary type must be the only remaining type with no parent nodes. |

## Accessors

### types

```ts theme={null}
get types(): Record<string, TypedDataField[]>
```

The types.

#### Returns

`Record`\<`string`, [`TypedDataField`](/sdk/content/interfaces/TypedDataField)\[]>

#### Source

[hash/typed-data.ts:244](https://github.com/dominant-strategies/quais.js/blob/c1c12d43f9d34c6baad2b0542bd6d0acd6fefcbf/src/hash/typed-data.ts#L244)

## Methods

### encode()

```ts theme={null}
encode(value): string
```

Return the fulled encoded `value` for the [**types**](/sdk/content/classes/TypedDataEncoder#types).

#### Parameters

| Parameter | Type                       | Description          |
| :-------- | :------------------------- | :------------------- |
| `value`   | `Record`\<`string`, `any`> | The value to encode. |

#### Returns

`string`

The encoded value.

#### Source

[hash/typed-data.ts:465](https://github.com/dominant-strategies/quais.js/blob/c1c12d43f9d34c6baad2b0542bd6d0acd6fefcbf/src/hash/typed-data.ts#L465)

***

### encodeData()

```ts theme={null}
encodeData(type, value): string
```

Return the encoded `value` for the `type`.

#### Parameters

| Parameter | Type     | Description                       |
| :-------- | :------- | :-------------------------------- |
| `type`    | `string` | The type to encode the value for. |
| `value`   | `any`    | The value to encode.              |

#### Returns

`string`

The encoded value.

#### Source

[hash/typed-data.ts:444](https://github.com/dominant-strategies/quais.js/blob/c1c12d43f9d34c6baad2b0542bd6d0acd6fefcbf/src/hash/typed-data.ts#L444)

***

### encodeType()

```ts theme={null}
encodeType(name): string
```

Return the full type for `name`.

#### Parameters

| Parameter | Type     | Description                        |
| :-------- | :------- | :--------------------------------- |
| `name`    | `string` | The name to get the full type for. |

#### Returns

`string`

The full type.

#### Source

[hash/typed-data.ts:431](https://github.com/dominant-strategies/quais.js/blob/c1c12d43f9d34c6baad2b0542bd6d0acd6fefcbf/src/hash/typed-data.ts#L431)

***

### getEncoder()

```ts theme={null}
getEncoder(type): (value) => string
```

Returnthe encoder for the specific `type`.

#### Parameters

| Parameter | Type     | Description                      |
| :-------- | :------- | :------------------------------- |
| `type`    | `string` | The type to get the encoder for. |

#### Returns

`Function`

The encoder for the type.

##### Parameters

| Parameter | Type  |
| :-------- | :---- |
| `value`   | `any` |

##### Returns

`string`

#### Source

[hash/typed-data.ts:365](https://github.com/dominant-strategies/quais.js/blob/c1c12d43f9d34c6baad2b0542bd6d0acd6fefcbf/src/hash/typed-data.ts#L365)

***

### hash()

```ts theme={null}
hash(value): string
```

Return the hash of the fully encoded `value` for the [**types**](/sdk/content/classes/TypedDataEncoder#types).

#### Parameters

| Parameter | Type                       | Description        |
| :-------- | :------------------------- | :----------------- |
| `value`   | `Record`\<`string`, `any`> | The value to hash. |

#### Returns

`string`

The hash of the value.

#### Source

[hash/typed-data.ts:475](https://github.com/dominant-strategies/quais.js/blob/c1c12d43f9d34c6baad2b0542bd6d0acd6fefcbf/src/hash/typed-data.ts#L475)

***

### hashStruct()

```ts theme={null}
hashStruct(name, value): string
```

Returns the hash of `value` for the type of `name`.

#### Parameters

| Parameter | Type                       | Description           |
| :-------- | :------------------------- | :-------------------- |
| `name`    | `string`                   | The name of the type. |
| `value`   | `Record`\<`string`, `any`> | The value to hash.    |

#### Returns

`string`

The hash of the value.

#### Source

[hash/typed-data.ts:455](https://github.com/dominant-strategies/quais.js/blob/c1c12d43f9d34c6baad2b0542bd6d0acd6fefcbf/src/hash/typed-data.ts#L455)

***

### visit()

```ts theme={null}
visit(value, callback): any
```

Call `calback` for each value in `value`, passing the type and component within `value`.

This is useful for replacing addresses or other transformation that may be desired on each component, based on
its type.

#### Parameters

| Parameter  | Type                       | Description                          |
| :--------- | :------------------------- | :----------------------------------- |
| `value`    | `Record`\<`string`, `any`> | The value to visit.                  |
| `callback` | (`type`, `data`) => `any`  | The callback to call for each value. |

#### Returns

`any`

The result of the callback.

#### Source

[hash/typed-data.ts:528](https://github.com/dominant-strategies/quais.js/blob/c1c12d43f9d34c6baad2b0542bd6d0acd6fefcbf/src/hash/typed-data.ts#L528)

***

### encode()

```ts theme={null}
static encode(
   domain, 
   types, 
   value): string
```

Return the fully encoded [EIP-712](https://eips.ethereum.org/EIPS/eip-712) `value` for `types` with `domain`.

#### Parameters

| Parameter | Type                                                                               | Description          |
| :-------- | :--------------------------------------------------------------------------------- | :------------------- |
| `domain`  | [`TypedDataDomain`](/sdk/content/interfaces/TypedDataDomain)                       | The domain to use.   |
| `types`   | `Record`\<`string`, [`TypedDataField`](/sdk/content/interfaces/TypedDataField)\[]> | The types to encode. |
| `value`   | `Record`\<`string`, `any`>                                                         | The value to encode. |

#### Returns

`string`

The encoded value.

#### Source

[hash/typed-data.ts:599](https://github.com/dominant-strategies/quais.js/blob/c1c12d43f9d34c6baad2b0542bd6d0acd6fefcbf/src/hash/typed-data.ts#L599)

***

### from()

```ts theme={null}
static from(types): TypedDataEncoder
```

Create a new **TypedDataEncoder** for `types`.

#### Parameters

| Parameter | Type                                                                               | Description          |
| :-------- | :--------------------------------------------------------------------------------- | :------------------- |
| `types`   | `Record`\<`string`, [`TypedDataField`](/sdk/content/interfaces/TypedDataField)\[]> | The types to encode. |

#### Returns

[`TypedDataEncoder`](/sdk/content/classes/TypedDataEncoder)

The encoder for the types.

#### Throws

If the types are invalid.

#### Source

[hash/typed-data.ts:539](https://github.com/dominant-strategies/quais.js/blob/c1c12d43f9d34c6baad2b0542bd6d0acd6fefcbf/src/hash/typed-data.ts#L539)

***

### getPayload()

```ts theme={null}
static getPayload(
   domain, 
   types, 
   value): any
```

Returns the JSON-encoded payload expected by nodes which implement the JSON-RPC
[EIP-712](https://eips.ethereum.org/EIPS/eip-712) method.

#### Parameters

| Parameter | Type                                                                               | Description          |
| :-------- | :--------------------------------------------------------------------------------- | :------------------- |
| `domain`  | [`TypedDataDomain`](/sdk/content/interfaces/TypedDataDomain)                       | The domain to use.   |
| `types`   | `Record`\<`string`, [`TypedDataField`](/sdk/content/interfaces/TypedDataField)\[]> | The types to encode. |
| `value`   | `Record`\<`string`, `any`>                                                         | The value to encode. |

#### Returns

`any`

The JSON-encoded payload.

#### Source

[hash/typed-data.ts:633](https://github.com/dominant-strategies/quais.js/blob/c1c12d43f9d34c6baad2b0542bd6d0acd6fefcbf/src/hash/typed-data.ts#L633)

***

### getPrimaryType()

```ts theme={null}
static getPrimaryType(types): string
```

Return the primary type for `types`.

#### Parameters

| Parameter | Type                                                                               | Description                            |
| :-------- | :--------------------------------------------------------------------------------- | :------------------------------------- |
| `types`   | `Record`\<`string`, [`TypedDataField`](/sdk/content/interfaces/TypedDataField)\[]> | The types to get the primary type for. |

#### Returns

`string`

The primary type.

#### Throws

If the types are invalid.

#### Source

[hash/typed-data.ts:550](https://github.com/dominant-strategies/quais.js/blob/c1c12d43f9d34c6baad2b0542bd6d0acd6fefcbf/src/hash/typed-data.ts#L550)

***

### hash()

```ts theme={null}
static hash(
   domain, 
   types, 
   value): string
```

Return the hash of the fully encoded [EIP-712](https://eips.ethereum.org/EIPS/eip-712) `value` for `types` with
`domain`.

#### Parameters

| Parameter | Type                                                                               | Description        |
| :-------- | :--------------------------------------------------------------------------------- | :----------------- |
| `domain`  | [`TypedDataDomain`](/sdk/content/interfaces/TypedDataDomain)                       | The domain to use. |
| `types`   | `Record`\<`string`, [`TypedDataField`](/sdk/content/interfaces/TypedDataField)\[]> | The types to hash. |
| `value`   | `Record`\<`string`, `any`>                                                         | The value to hash. |

#### Returns

`string`

The hash of the value.

#### Source

[hash/typed-data.ts:616](https://github.com/dominant-strategies/quais.js/blob/c1c12d43f9d34c6baad2b0542bd6d0acd6fefcbf/src/hash/typed-data.ts#L616)

***

### hashDomain()

```ts theme={null}
static hashDomain(domain): string
```

Return the domain hash for `domain`.

#### Parameters

| Parameter | Type                                                         | Description         |
| :-------- | :----------------------------------------------------------- | :------------------ |
| `domain`  | [`TypedDataDomain`](/sdk/content/interfaces/TypedDataDomain) | The domain to hash. |

#### Returns

`string`

The hash of the domain.

#### Throws

If the domain is invalid.

#### Source

[hash/typed-data.ts:573](https://github.com/dominant-strategies/quais.js/blob/c1c12d43f9d34c6baad2b0542bd6d0acd6fefcbf/src/hash/typed-data.ts#L573)

***

### hashStruct()

```ts theme={null}
static hashStruct(
   name, 
   types, 
   value): string
```

Return the hashed struct for `value` using `types` and `name`.

#### Parameters

| Parameter | Type                                                                               | Description           |
| :-------- | :--------------------------------------------------------------------------------- | :-------------------- |
| `name`    | `string`                                                                           | The name of the type. |
| `types`   | `Record`\<`string`, [`TypedDataField`](/sdk/content/interfaces/TypedDataField)\[]> | The types to hash.    |
| `value`   | `Record`\<`string`, `any`>                                                         | The value to hash.    |

#### Returns

`string`

The hash of the value.

#### Source

[hash/typed-data.ts:562](https://github.com/dominant-strategies/quais.js/blob/c1c12d43f9d34c6baad2b0542bd6d0acd6fefcbf/src/hash/typed-data.ts#L562)
