decodeError method

List? decodeError(
  1. dynamic error
)

Decodes the error data based on the error fragment in the contract ABI.

Implementation

List<dynamic>? decodeError(dynamic error) {
  try {
    if (error is String) {
      final inBytes = BytesUtils.fromHexString(error);
      final errorSelector = inBytes.sublist(0, ABIConst.selectorLength);
      if (bytesEqual(errorSelector, revert.selector)) {
        return revert.decodeError(inBytes);
      }
      final errorFragment = errors.singleWhere(
          (element) => bytesEqual(element.selector, errorSelector));

      return errorFragment.decodeError(inBytes);
    }
  } catch (e) {
    return null;
  }
  return null;
}