decodeError method

String? decodeError(
  1. Uint8List data
)
inherited

Decodes an error from revert data.

Implementation

String? decodeError(Uint8List data) {
  // First try standard Error(string) and Panic(uint256)
  final standardError = AbiDecoder.decodeError(data);
  if (standardError != null) {
    return standardError;
  }

  // Try custom errors
  if (data.length >= 4) {
    final selector = data.sublist(0, 4);

    for (final error in errors) {
      final expectedSelector =
          AbiEncoder.getFunctionSelector(error.signature);
      if (_bytesEqual(selector, expectedSelector)) {
        try {
          final decoded = AbiDecoder.decode(error.inputs, data.sublist(4));
          final args = decoded.map((v) => v.toString()).join(', ');
          return '${error.name}($args)';
        } on Exception catch (_) {
          return error.name;
        }
      }
    }
  }

  return null;
}