EIPs Explained

ERC-55 · Final · ERC · 2016-01-14

ERC-55: Mixed-case checksum address encoding

Adds a checksum to Ethereum addresses by capitalizing some hex letters, so wallets can catch most typos without changing the address format.

What problem does it solve?

An Ethereum address is just 20 bytes written as 40 hex characters. Raw hex has no built-in error detection. If you mistype one character, the result is still a valid address, and any ETH you send there is most likely lost forever.

EIP-55 adds a checksum without changing the length or the characters of the address. Hex is case-insensitive, so the case of each letter is free to carry extra information. Old software that ignores case keeps working, and new software can check the case.

How it works

  1. Take the address as lowercase hex without 0x (40 ASCII characters).
  2. Hash that ASCII string with Keccak-256.
  3. For each character at position i:
    • digits 0-9 stay as they are;
    • letters a-f become uppercase if the i-th hex digit of the hash is 8 or higher, and stay lowercase otherwise.

The result looks like 0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed. A wallet that receives a mixed-case address recomputes the checksum and rejects it if the case does not match.

The spec gives the numbers: an address has about 15 check bits on average, and a mistyped address passes by accident only about 0.0247% of the time. That is weaker than a 4-byte checksum, but it costs nothing in length.

Sample code

A minimal implementation (TypeScript, ethers v6 for Keccak):

import { keccak256, toUtf8Bytes } from "ethers";

function toChecksumAddress(address: string): string {
  const hex = address.toLowerCase().replace(/^0x/, "");
  const hash = keccak256(toUtf8Bytes(hex)).slice(2); // hash the ASCII string, not the bytes
  let out = "0x";
  for (let i = 0; i < hex.length; i++) {
    out += parseInt(hash[i], 16) >= 8 ? hex[i].toUpperCase() : hex[i];
  }
  return out;
}

toChecksumAddress("0xfb6916095ca1df60bb79ce92ce3ea74c37c5d359");
// "0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359"

In practice, use the library function. It also throws on a bad checksum:

import { getAddress } from "ethers";

getAddress("0xfb6916095ca1df60bb79ce92ce3ea74c37c5d359"); // returns checksummed form
getAddress("0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d358"); // throws: bad address checksum

Things to know

  • All-lowercase and all-uppercase addresses carry no checksum. Most libraries accept them as "unchecked" and only validate mixed-case input.
  • The hash input is the lowercase hex string, not the 20 raw bytes. Hashing the bytes is a common bug.
  • The checksum does not depend on the chain, so the same address is valid on every EVM chain. EIP-1191 proposes an optional chain-specific variant, but most wallets use plain EIP-55.
  • EIP-55 is used almost everywhere: wallets, block explorers, Solidity (which requires checksummed address literals) and RPC methods such as EIP-747 wallet_watchAsset.

#address #checksum #wallet #encoding

Details

Authors
Vitalik Buterin <[email protected]>, Alex Van de Sande <[email protected]>
Status
Final
Type
Standards Track / ERC
Created
2016-01-14
Required by

Machine-readable: Markdown · JSON