Skip to main content
Portal integrates with Blockaid to provide transaction security evaluation. This allows you to scan transactions for potential security risks before sending them, helping to identify malicious contracts, phishing attempts, and other threats.

Transaction Evaluation

The evaluateTransaction method analyzes a transaction and returns a risk assessment.

Basic Evaluation

import 'package:portal_flutter/portal_flutter.dart';

final portal = Portal();

// Evaluate a transaction before sending
final result = await portal.evaluateTransaction(
  chainId: 'eip155:1',
  to: '0xContractAddress',
  value: '0x0',
  data: '0xa9059cbb...', // Contract call data
);

print('Result: ${result.result}');
print('Classification: ${result.classification}');
print('Reason: ${result.reason}');
print('Description: ${result.description}');

Full Transaction Evaluation

For complete transaction parameters:
final result = await portal.evaluateTransaction(
  chainId: 'eip155:1',
  to: '0xContractAddress',
  from: '0xYourAddress',
  value: '0x10',
  data: '0x',
  gas: '0x5208',
  maxFeePerGas: '0x3B9ACA00',
  maxPriorityFeePerGas: '0x3B9ACA00',
  operationType: PortalEvaluateTransactionOperationType.all,
);

Operation Types

You can specify what type of evaluation to perform:
Operation TypeDescription
validationOnly validate the transaction structure and parameters
simulationOnly simulate the transaction execution
allPerform both validation and simulation
// Validation only
final validationResult = await portal.evaluateTransaction(
  chainId: 'eip155:1',
  to: '0xContractAddress',
  operationType: PortalEvaluateTransactionOperationType.validation,
);

// Simulation only
final simulationResult = await portal.evaluateTransaction(
  chainId: 'eip155:1',
  to: '0xContractAddress',
  operationType: PortalEvaluateTransactionOperationType.simulation,
);

Evaluating Before Sending

A common pattern is to evaluate a transaction before sending it:
import 'package:portal_flutter/portal_flutter.dart';

final portal = Portal();

Future<String?> sendWithEvaluation({
  required String chainId,
  required String to,
  required String value,
}) async {
  // First, evaluate the transaction
  final evaluation = await portal.evaluateTransaction(
    chainId: chainId,
    to: to,
    value: value,
    operationType: PortalEvaluateTransactionOperationType.all,
  );

  // Check the risk assessment
  if (evaluation.result == 'Malicious') {
    print('Transaction blocked due to security risks');
    print('Reason: ${evaluation.reason}');
    print('Description: ${evaluation.description}');
    return null;
  }

  if (evaluation.result == 'Warning') {
    print('Warning: ${evaluation.description}');
    // Optionally prompt user to confirm
  }

  // Proceed with the transaction
  final txHash = await portal.sendTransaction(
    chainId: chainId,
    to: to,
    value: value,
  );

  return txHash;
}
Transaction evaluation is a security tool, not a guarantee. Always exercise caution when interacting with unknown contracts.

Understanding Results

The evaluation result includes:
  • result: The overall assessment (e.g., Benign, Warning, Malicious)
  • reason: The reason for the assessment
  • classification: The classification category of the risk
  • description: A human-readable description of the findings
  • status: The status of the evaluation
final result = await portal.evaluateTransaction(
  chainId: 'eip155:1',
  to: '0xContractAddress',
);

// Check the result
if (result.result == 'Benign') {
  print('Transaction appears safe');
} else if (result.result == 'Warning') {
  print('Proceed with caution');
  print('Classification: ${result.classification}');
  print('Description: ${result.description}');
} else if (result.result == 'Malicious') {
  print('Transaction blocked');
  print('Reason: ${result.reason}');
}
Related Documentation