This content originally appeared on DEV Community and was authored by drake
from eth_utils import keccak, to_checksum_address
def explain_checksum_address(address):
"""
展示 EIP-55 校验和地址的生成过程
"""
# 移除 0x 前缀,转换为小写
address_lower = address.lower().replace('0x', '')
print(f"1. 原始地址(小写): {address_lower}\n")
# 对小写地址进行 Keccak-256 哈希
hash_bytes = keccak(text=address_lower)
hash_hex = hash_bytes.hex()
print(f"2. 地址的Keccak-256哈希: {hash_hex}\n")
# 根据哈希值决定每个字符的大小写
checksum_address = '0x'
print("3. 大小写转换规则:")
for i, char in enumerate(address_lower):
if char in '0123456789':
# 数字保持不变
checksum_address += char
print(f" 位置{i}: '{char}' -> '{char}' (数字)")
else:
# 字母:哈希对应位置的值 >= 8 则大写,否则小写
hash_digit = int(hash_hex[i], 16)
if hash_digit >= 8:
checksum_address += char.upper()
print(f" 位置{i}: '{char}' -> '{char.upper()}' (哈希值{hash_digit} >= 8)")
else:
checksum_address += char
print(f" 位置{i}: '{char}' -> '{char}' (哈希值{hash_digit} < 8)")
print(f"\n4. 最终校验和地址: {checksum_address}")
return checksum_address
# 示例
address = "0x5aaeb6053f3e94c9b9a09f33669435e7ef1beaed"
result = explain_checksum_address(address)
This content originally appeared on DEV Community and was authored by drake
Print
Share
Comment
Cite
Upload
Translate
Updates
There are no updates yet.
Click the Upload button above to add an update.
APA
MLA
drake | Sciencx (2025-09-30T04:38:39+00:00) EVM 小写地址转换为标准地址:(大小写混合). Retrieved from https://www.scien.cx/2025/09/30/evm-%e5%b0%8f%e5%86%99%e5%9c%b0%e5%9d%80%e8%bd%ac%e6%8d%a2%e4%b8%ba%e6%a0%87%e5%87%86%e5%9c%b0%e5%9d%80%ef%bc%9a%ef%bc%88%e5%a4%a7%e5%b0%8f%e5%86%99%e6%b7%b7%e5%90%88%ef%bc%89/
" » EVM 小写地址转换为标准地址:(大小写混合)." drake | Sciencx - Tuesday September 30, 2025, https://www.scien.cx/2025/09/30/evm-%e5%b0%8f%e5%86%99%e5%9c%b0%e5%9d%80%e8%bd%ac%e6%8d%a2%e4%b8%ba%e6%a0%87%e5%87%86%e5%9c%b0%e5%9d%80%ef%bc%9a%ef%bc%88%e5%a4%a7%e5%b0%8f%e5%86%99%e6%b7%b7%e5%90%88%ef%bc%89/
HARVARDdrake | Sciencx Tuesday September 30, 2025 » EVM 小写地址转换为标准地址:(大小写混合)., viewed ,<https://www.scien.cx/2025/09/30/evm-%e5%b0%8f%e5%86%99%e5%9c%b0%e5%9d%80%e8%bd%ac%e6%8d%a2%e4%b8%ba%e6%a0%87%e5%87%86%e5%9c%b0%e5%9d%80%ef%bc%9a%ef%bc%88%e5%a4%a7%e5%b0%8f%e5%86%99%e6%b7%b7%e5%90%88%ef%bc%89/>
VANCOUVERdrake | Sciencx - » EVM 小写地址转换为标准地址:(大小写混合). [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/09/30/evm-%e5%b0%8f%e5%86%99%e5%9c%b0%e5%9d%80%e8%bd%ac%e6%8d%a2%e4%b8%ba%e6%a0%87%e5%87%86%e5%9c%b0%e5%9d%80%ef%bc%9a%ef%bc%88%e5%a4%a7%e5%b0%8f%e5%86%99%e6%b7%b7%e5%90%88%ef%bc%89/
CHICAGO" » EVM 小写地址转换为标准地址:(大小写混合)." drake | Sciencx - Accessed . https://www.scien.cx/2025/09/30/evm-%e5%b0%8f%e5%86%99%e5%9c%b0%e5%9d%80%e8%bd%ac%e6%8d%a2%e4%b8%ba%e6%a0%87%e5%87%86%e5%9c%b0%e5%9d%80%ef%bc%9a%ef%bc%88%e5%a4%a7%e5%b0%8f%e5%86%99%e6%b7%b7%e5%90%88%ef%bc%89/
IEEE" » EVM 小写地址转换为标准地址:(大小写混合)." drake | Sciencx [Online]. Available: https://www.scien.cx/2025/09/30/evm-%e5%b0%8f%e5%86%99%e5%9c%b0%e5%9d%80%e8%bd%ac%e6%8d%a2%e4%b8%ba%e6%a0%87%e5%87%86%e5%9c%b0%e5%9d%80%ef%bc%9a%ef%bc%88%e5%a4%a7%e5%b0%8f%e5%86%99%e6%b7%b7%e5%90%88%ef%bc%89/. [Accessed: ]
rf:citation » EVM 小写地址转换为标准地址:(大小写混合) | drake | Sciencx | https://www.scien.cx/2025/09/30/evm-%e5%b0%8f%e5%86%99%e5%9c%b0%e5%9d%80%e8%bd%ac%e6%8d%a2%e4%b8%ba%e6%a0%87%e5%87%86%e5%9c%b0%e5%9d%80%ef%bc%9a%ef%bc%88%e5%a4%a7%e5%b0%8f%e5%86%99%e6%b7%b7%e5%90%88%ef%bc%89/ |
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.