Introduction
Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.
I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.
I also build and publish a variety of tools, libraries, and open-source projects.
EIP-55 defines a checksum encoding for Ethereum addresses that uses a mixture of uppercase and lowercase hexadecimal characters.
This article translates, summarizes, and expands on the following specification.
More ERC explainers:
Specification
import eth_utils
def checksum_encode(addr): # Takes a 20-byte binary address as input
hex_addr = addr.hex()
checksummed_buffer = ""
# Treat the hex address as ascii/utf-8 for keccak256 hashing
hashed_address = eth_utils.keccak(text=hex_addr).hex()
# Iterate over each character in the hex address
for nibble_index, character in enumerate(hex_addr):
if character in "0123456789":
# We can't upper-case the decimal digits
checksummed_buffer += character
elif character in "abcdef":
# Check if the corresponding hex digit (nibble) in the hash is 8 or higher
hashed_address_nibble = int(hashed_address[nibble_index], 16)
if hashed_address_nibble > 7:
checksummed_buffer += character.upper()
else:
checksummed_buffer += character
else:
raise eth_utils.ValidationError(
f"Unrecognized hex character {character!r} at position {nibble_index}"
)
return "0x" + checksummed_buffer
def test(addr_str):
addr_bytes = eth_utils.to_bytes(hexstr=addr_str)
checksum_encoded = checksum_encode(addr_bytes)
assert checksum_encoded == addr_str, f"{checksum_encoded} != expected {addr_str}"
test("0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed")
test("0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359")
test("0xdbF03B407c01E7cD3CBea99509d93f8DDDC8C6FB")
test("0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb")This Python example implements Ethereum address checksum encoding and provides tests for the implementation.
checksum_encode
- The function accepts a 20-byte binary address and produces its checksummed representation.
- It converts the address into a lowercase hexadecimal string using
addr.hex(). - It computes the Keccak-256 hash of that string, treating it as ASCII/UTF-8 text rather than hashing the original 20 binary bytes.
- It iterates over the hexadecimal characters:
- Decimal digits (
0through9) remain unchanged. - For letters (
athroughf), it examines the corresponding four-bit nibble of the hash. If the nibble is at least 8, the letter is converted to uppercase. Otherwise, it remains lowercase. - An unrecognized character results in a validation error.
- Decimal digits (
- Finally, the function prepends
0xand returns the checksummed address.
test
- The test function accepts an address string and checks whether
checksum_encodeproduces the expected representation. - It converts the hexadecimal address to bytes and calls
checksum_encode. - If the result differs from the expected address, the assertion fails and reports the mismatch.
The supplied test cases exercise the checksum encoder using known Ethereum addresses.
The encoding procedure can be summarized as follows.
- Convert the address into a hexadecimal string.
- For example,
0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAedbecomes5aaeb6053f3e94c9b9a09f33669435e7ef1beaedafter normalization.
- For example,
- Compute the Keccak-256 hash of the lowercase hexadecimal text, without the
0xprefix. - Associate each address character with the corresponding four-bit nibble of the hash.
- Preserve decimal digits unchanged. For example, the digit
5remains5. - For each hexadecimal letter, examine the most significant bit of its corresponding hash nibble. If that bit is one (the nibble is at least 8), convert the letter to uppercase; otherwise, keep it lowercase.
- In the example address, the first
astays lowercase while the followingabecomes uppercase. - A hexadecimal letter such as
fremains lowercase when its corresponding hash nibble is below 8.
- In the example address, the first
- Reject invalid hexadecimal characters rather than treating them as valid address data.
The result encodes checksum information through letter casing while preserving the original address value.
Additional considerations
Advantages
- Compatibility with existing hexadecimal parsers that accept mixed-case characters makes incremental adoption straightforward.
- The address retains its original length of 40 hexadecimal characters, excluding the
0xprefix. - The specification estimates an average of 15 checksum bits per address. The probability of a random mistyped address accidentally passing the check is approximately 0.0247%.
- This is about a 50-fold improvement over ICAP's error-detection probability as discussed in EIP-55, although it is weaker than a four-byte checksum.
Mixed-case encoding preserves the familiar hexadecimal address format while improving detection of accidental errors. It does not authenticate an address or prevent an attacker from generating a different, correctly checksummed address.
Implementation
const createKeccakHash = require('keccak')
function toChecksumAddress (address) {
address = address.toLowerCase().replace('0x', '')
var hash = createKeccakHash('keccak256').update(address).digest('hex')
var ret = '0x'
for (var i = 0; i < address.length; i++) {
if (parseInt(hash[i], 16) >= 8) {
ret += address[i].toUpperCase()
} else {
ret += address[i]
}
}
return ret
}This JavaScript example implements the checksum encoder through the toChecksumAddress function.
Importing createKeccakHash
The keccak library provides the Keccak-256 hashing function.
toChecksumAddress
The function accepts an Ethereum address string and returns its checksummed form.
Normalizing the address
The function converts the string to lowercase and removes the 0x prefix.
Hashing the address
createKeccakHash('keccak256')initializes the hash function.update(address)supplies the normalized hexadecimal text.digest('hex')returns the hash as a hexadecimal string.
Computing the checksum
- The loop examines each address character and its corresponding hash character.
parseInt(hash[i], 16)converts the hash character to its numerical nibble value.- When the value is at least 8, the corresponding address character is converted to uppercase and appended to
ret. - Otherwise, the character is appended unchanged. Decimal digits are unaffected by case conversion.
Returning the address
The resulting string includes the 0x prefix and the checksummed hexadecimal characters.
This is an encoding example. A production implementation should additionally validate the input's length and hexadecimal format and distinguish checksum generation from checksum validation.
> toChecksumAddress('0xfb6916095ca1df60bb79ce92ce3ea74c37c5d359')
'0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359'The input to Keccak-256 is the lowercase hexadecimal address text encoded as ASCII, without the prefix.
var hash = createKeccakHash('keccak256').update(Buffer.from(address.toLowerCase(), 'ascii')).digest()Tests
# All caps
0x52908400098527886E0F7030069857D2E4169EE7
0x8617E340B3D01FA5F11F306F4090FD50E238070D
# All Lower
0xde709f2102306220921060314715629080e2fb77
0x27b1fdb04752bbc536007a920d24acb045561c26
# Normal
0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed
0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359
0xdbF03B407c01E7cD3CBea99509d93f8DDDC8C6FB
0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDbSome valid checksummed addresses happen to contain only uppercase letters or only lowercase letters. Mixed case is therefore not a requirement for every individual checksummed address.
Citation
Vitalik Buterin vitalik.buterin@ethereum.org, Alex Van de Sande avsa@ethereum.org, "ERC-55: Mixed-case checksum address encoding," Ethereum Improvement Proposals, no. 55, January 2016. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-55.
Conclusion
EIP-55 uses the case of hexadecimal letters to encode a checksum without increasing the length of an Ethereum address. It helps detect accidental transcription errors.
Questions are welcome via Twitter @cardene777.
Other publications:


