simulate method
Simulates a contract function call.
Implementation
Future<SimulateResult> simulate(
String functionName,
List<dynamic> args, {
String? from,
BigInt? value,
String block = 'latest',
}) async {
final function = _getFunction(functionName);
final callData = AbiEncoder.encodeFunction(function.signature, args);
final request = CallRequest(
from: from,
to: address,
data: callData,
value: value,
);
try {
final result = await publicClient.call(request, block);
final decoded = AbiDecoder.decodeFunction(function.outputs, result);
// Estimate gas for the call
final gasUsed = await publicClient.estimateGas(request);
return SimulateResult(
result: decoded,
gasUsed: gasUsed,
success: true,
);
} on Exception catch (e) {
// Try to decode error message
String? revertReason;
if (e.toString().contains('execution reverted')) {
// Extract revert data if available
// This is a simplified implementation
revertReason = e.toString();
}
return SimulateResult(
result: [],
gasUsed: BigInt.zero,
success: false,
revertReason: revertReason,
);
}
}