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

# signMessage / signTypedData

> Sign messages and typed data.

## signMessage

### Function Signature

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

### Description

Signs a personal message using the `personal_sign` RPC method, which prepends the standard Ethereum message prefix before signing.

### Parameters

| Parameter | Type     | Required | Description                             |
| --------- | -------- | -------- | --------------------------------------- |
| `chainId` | `String` | Yes      | The chain ID in CAIP-2 format           |
| `message` | `String` | Yes      | The message to sign (plain text or hex) |

### Returns

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

### Example

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

final portal = Portal();

final signature = await portal.signMessage(
  chainId: 'eip155:1',
  message: 'Hello, Portal!',
);

print('Signature: $signature');
```

***

## signTypedData

### Function Signature

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

### Description

Signs typed data according to the EIP-712 standard using the `eth_signTypedData_v4` RPC method.

### Parameters

| Parameter   | Type     | Required | Description                     |
| ----------- | -------- | -------- | ------------------------------- |
| `chainId`   | `String` | Yes      | The chain ID in CAIP-2 format   |
| `typedData` | `String` | Yes      | The typed data as a JSON string |

### Returns

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

### Example

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

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');
```

## Errors

| Code                 | Description                    |
| -------------------- | ------------------------------ |
| `NOT_INITIALIZED`    | Portal was not initialized     |
| `SIGNING_FAILED`     | The signing operation failed   |
| `INVALID_TYPED_DATA` | The typed data JSON is invalid |

## Related

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