getFunctionSelector static method

Uint8List getFunctionSelector(
  1. String signature
)

Gets the 4-byte function selector from a signature. Per Solidity ABI specification, the signature is UTF-8 encoded before hashing.

Implementation

static Uint8List getFunctionSelector(String signature) {
  final hash = Keccak256.hash(Uint8List.fromList(utf8.encode(signature)));
  return BytesUtils.slice(hash, 0, 4);
}