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

# signTypedData

> Sign EIP-712 typed structured data with the Portal Flutter SDK.

## Function Signature

```dart theme={null}
Future<String> signTypedData({
  required String chainId,
  required String typedData,
})
```

## Description

Signs typed structured data according to the [EIP-712](https://eips.ethereum.org/EIPS/eip-712) standard using the `eth_signTypedData_v4` RPC method. EIP-712 signatures are commonly used for gasless approvals, off-chain orders, and structured authentication messages.

The Flutter SDK accepts the typed data payload as a JSON-encoded string. Use `dart:convert`'s `jsonEncode` to serialize a `Map` into the expected format.

## Parameters

| Parameter   | Type     | Required | Description                                              |
| ----------- | -------- | -------- | -------------------------------------------------------- |
| `chainId`   | `String` | Yes      | The chain ID in CAIP-2 format (e.g., `eip155:1`).        |
| `typedData` | `String` | Yes      | The EIP-712 typed data payload as a JSON-encoded string. |

## Returns

**`String`** — The signature as a hex string.

## Example

### Basic example

```dart theme={null}
import 'dart:convert';
import 'package:portal_flutter/portal_flutter.dart';

final portal = Portal();

final typedData = jsonEncode({
  'types': {
    'EIP712Domain': [
      {'name': 'name', 'type': 'string'},
      {'name': 'version', 'type': 'string'},
      {'name': 'chainId', 'type': 'uint256'},
    ],
    'Message': [
      {'name': 'content', 'type': 'string'},
    ],
  },
  'primaryType': 'Message',
  'domain': {
    'name': 'Example App',
    'version': '1',
    'chainId': 1,
  },
  'message': {
    'content': 'Hello, Portal!',
  },
});

final signature = await portal.signTypedData(
  chainId: 'eip155:1',
  typedData: typedData,
);

print('EIP-712 Signature: $signature');
```

### Permit (ERC-20 gasless approval)

A common use of EIP-712 is signing an ERC-20 `permit` message to grant token approvals without an on-chain transaction:

```dart theme={null}
import 'dart:convert';
import 'package:portal_flutter/portal_flutter.dart';

Future<String> signPermit({
  required Portal portal,
  required String owner,
  required String spender,
  required String tokenAddress,
  required int value,
  required int nonce,
  required int deadline,
}) async {
  final typedData = jsonEncode({
    'primaryType': 'Permit',
    'types': {
      'EIP712Domain': [
        {'name': 'name', 'type': 'string'},
        {'name': 'version', 'type': 'string'},
        {'name': 'chainId', 'type': 'uint256'},
        {'name': 'verifyingContract', 'type': 'address'},
      ],
      'Permit': [
        {'name': 'owner', 'type': 'address'},
        {'name': 'spender', 'type': 'address'},
        {'name': 'value', 'type': 'uint256'},
        {'name': 'nonce', 'type': 'uint256'},
        {'name': 'deadline', 'type': 'uint256'},
      ],
    },
    'domain': {
      'name': 'MyToken',
      'version': '1',
      'chainId': 1,
      'verifyingContract': tokenAddress,
    },
    'message': {
      'owner': owner,
      'spender': spender,
      'value': value,
      'nonce': nonce,
      'deadline': deadline,
    },
  });

  return portal.signTypedData(
    chainId: 'eip155:1',
    typedData: typedData,
  );
}
```

## Errors

Throws a `PortalException` on failure:

| Code                    | Description                   |
| ----------------------- | ----------------------------- |
| `NOT_INITIALIZED`       | Portal was not initialized.   |
| `SIGN_TYPED_DATA_ERROR` | The signing operation failed. |

```dart theme={null}
try {
  final signature = await portal.signTypedData(
    chainId: 'eip155:1',
    typedData: typedData,
  );
} on PortalException catch (e) {
  print('Failed to sign typed data: ${e.code} - ${e.message}');
}
```

## Implementation Notes

* The `chainId` value inside the `domain` object should match the chain you are signing on. Mismatches will produce a signature that will not verify on-chain.
* The Portal Flutter SDK signs typed data via the `eth_signTypedData_v4` RPC method — only EIP-712 v4 is supported.
* Verify the signature server-side before using it to authorize an action.

## Related

* [signMessage](./signmessage)
* [rawSign](./rawsign)
* [request](./request)
* [Sign a transaction guide](../guide/sign-a-transaction)
