Skip to main content

signMessage

Function Signature

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

ParameterTypeRequiredDescription
chainIdStringYesThe chain ID in CAIP-2 format
messageStringYesThe message to sign (plain text or hex)

Returns

String - The signature as a hex string.

Example

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

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

ParameterTypeRequiredDescription
chainIdStringYesThe chain ID in CAIP-2 format
typedDataStringYesThe typed data as a JSON string

Returns

String - The signature as a hex string.

Example

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

CodeDescription
NOT_INITIALIZEDPortal was not initialized
SIGNING_FAILEDThe signing operation failed
INVALID_TYPED_DATAThe typed data JSON is invalid