toChecksumAddress static method
encode the address to checksumed address that is compatible with eip-55
Implementation
static String toChecksumAddress(String input) {
String body = remove0x(input).toLowerCase();
final digest = KeccakDigest(256);
var x = utf8.encode(body);
var h = digest.process(x);
String hash = bytesToHex(h);
String parts = '0x';
for (int i = 0; i < body.length; i++) {
// loop over body.
if (int.parse(hash.substring(i, i + 1), radix: 16) >= 8) {
parts = parts + (body.substring(i, i + 1).toUpperCase());
} else {
parts = parts + (body.substring(i, i + 1));
}
}
return parts;
}