normalizeSuiAddress function

String normalizeSuiAddress(
  1. String value, [
  2. bool forceAdd0x = false
])

Perform the following operations:

  1. Make the address lower case
  2. Prepend 0x if the string does not start with 0x.
  3. Add more zeros if the length of the address(excluding 0x) is less than SUI_ADDRESS_LENGTH

WARNING: if the address value itself starts with 0x, e.g., 0x0x, the default behavior is to treat the first 0x not as part of the address. The default behavior can be overridden by setting forceAdd0x to true

Implementation

String normalizeSuiAddress(
  String value,
  [bool forceAdd0x = false]
) {
  String address = value.toLowerCase();
  if (!forceAdd0x && address.startsWith('0x')) {
    address = address.substring(2);
  }
  return "0x${address.padLeft(SUI_ADDRESS_LENGTH * 2, '0')}";
}