toChecksumAddress function
Implementation
String toChecksumAddress(String address) {
if (!address.startsWith("0x")) {
throw ArgumentError("not an EVM address");
}
final stripAddress = address.replaceFirst("0x", "").toLowerCase();
final Uint8List keccakHash = keccakUtf8(stripAddress);
final String keccakHashHex = convert.hex.encode(keccakHash);
String checksumAddress = "0x";
for (var i = 0; i < stripAddress.length; i++) {
final bool high = int.parse(keccakHashHex[i], radix: 16) >= 8;
checksumAddress += (high ? stripAddress[i].toUpperCase() : stripAddress[i]);
}
return checksumAddress;
}