encode method

  1. @override
Uint8List encode(
  1. dynamic obj
)
override

Encode values with ABI rules based on the ABI type schemes @return byte[] of ABI encoding @throws IllegalArgumentException if encoder cannot infer the type from obj

Implementation

@override
Uint8List encode(dynamic obj) {
  if (obj is! int && obj is! BigInt) {
    throw ArgumentError('cannot infer type for bool abi value encode');
  }

  var value = obj is BigInt ? obj.toInt() : obj as int;

  if (value < 0 || value > 255) {
    throw ArgumentError('$value cannot be encoded into a byte');
  }

  return Uint8List.fromList([value]);
}