toHex function

String toHex(
  1. EthereumAddress address
)

Returns the plain hex address with 0x prefix (lowercase).

Implementation

String toHex(EthereumAddress address) {
  final dynamic d = address;
  try {
    final v = d.hex;
    if (v is String) return v;
  } catch (_) {}
  try {
    final v = d.with0x;
    if (v is String) return v;
  } catch (_) {}
  try {
    final v = d.hexNo0x;
    if (v is String) return '0x$v';
  } catch (_) {}
  try {
    final v = d.without0x;
    if (v is String) return '0x$v';
  } catch (_) {}
  try {
    final bytes = d.addressBytes as Uint8List?;
    if (bytes != null) {
      return '0x${bytes.map((b) => b.toRadixString(16).padLeft(2, '0')).join()}';
    }
  } catch (_) {}
  try {
    final bytes = d.value as Uint8List?;
    if (bytes != null) {
      return '0x${bytes.map((b) => b.toRadixString(16).padLeft(2, '0')).join()}';
    }
  } catch (_) {}
  return address.toString();
}