Skip to main content

Function Signature

Future<PortalProviderResponse> request({
  required String chainId,
  required String method,  // 'eth_signUserOperation'
  required List<Object?> params,
  String? signatureApprovalMemo,
})

Description

Signs an ERC-4337 UserOperation using the client’s MPC key without broadcasting it to the network. This method is invoked via portal.request() with the method set to eth_signUserOperation. The signed UserOperation can then be submitted through a separate backend (e.g., Pimlico or a custom bundler endpoint).
This method requires the client to be created with Account Abstraction enabled (isAccountAbstracted: true). Non-AA clients will receive a METHOD_UNSUPPORTED error.

Parameters

The params array takes a single object with the following fields:
ParameterTypeRequiredDescription
toStringYesThe recipient or contract address
valueStringNoValue in wei (hex-encoded)
dataStringNoCalldata (hex-encoded)
gasStringNoGas limit (hex-encoded)
maxFeePerGasStringNoMax fee per gas for EIP-1559 (hex-encoded)
maxPriorityFeePerGasStringNoMax priority fee for EIP-1559 (hex-encoded)
nonceStringNoTransaction nonce (hex-encoded)

Returns

PortalProviderResponse - An object containing:
PropertyTypeDescription
resultdynamicA hex-encoded JSON string containing the signed UserOperation
errordynamicError information if the call failed

Example

import 'package:portal_flutter/portal_flutter.dart';

final portal = Portal();

// Sign a UserOperation on Sepolia testnet
final result = await portal.request(
  chainId: 'eip155:11155111',
  method: 'eth_signUserOperation',
  params: [
    {
      'to': '0xRecipientAddress',
      'value': '0x0',
      'data': '0x',
    }
  ],
);

if (result.error != null) {
  print('Error: ${result.error}');
} else {
  print('Signed UserOp: ${result.result}');
}

With EIP-1559 Gas Parameters

final result = await portal.request(
  chainId: 'eip155:11155111',
  method: 'eth_signUserOperation',
  params: [
    {
      'to': '0xRecipientAddress',
      'value': '0xDE0B6B3A7640000', // 1 ETH in wei
      'data': '0x',
      'maxFeePerGas': '0x3B9ACA00',
      'maxPriorityFeePerGas': '0x3B9ACA00',
    }
  ],
);

Errors

CodeDescription
METHOD_UNSUPPORTEDThe client does not have Account Abstraction enabled
NOT_INITIALIZEDPortal was not initialized
RPC_ERRORThe RPC call returned an error