cchecksum
cchecksum is a Python library that provides an approximately 18x faster, C-implemented drop-in replacement for `eth_utils.to_checksum_address`. It ensures full API compatibility, raising the exact same exceptions as the original `eth_utils` function. Currently at version 0.4.3, the library is actively maintained with a focus on performance optimizations and broad platform compatibility through pre-built wheels.
Common errors
-
ModuleNotFoundError: No module named 'cchecksum'
cause The cchecksum package is not installed in the current Python environment.fixRun `pip install cchecksum`. -
ImportError: cannot import name 'to_checksum_address' from 'cchecksum'
cause Incorrect import statement or a damaged installation. The primary function is `to_checksum_address`.fixVerify the import statement is exactly `from cchecksum import to_checksum_address`. If it persists, try reinstalling `cchecksum`. -
ModuleNotFoundError: No module named 'eth_hash'
cause cchecksum relies on `eth-hash` for its internal hashing, and `eth-hash` was not installed as a dependency, potentially due to an old `pip` or incomplete install prior to `v0.3.5`.fixEnsure `eth-hash` is installed: `pip install eth-hash`. Reinstalling `cchecksum` (`pip install cchecksum`) should also pull its dependencies. -
error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": ...
cause The installation failed because a C compiler is needed to compile cchecksum's C/Cython extensions, and a pre-built wheel was not available for the specific environment.fixInstall the required C/C++ build tools for your operating system. For Windows, download and install 'Microsoft C++ Build Tools'. For Linux, install development packages like `build-essential` (Debian/Ubuntu) or `gcc` (CentOS/Fedora).
Warnings
- breaking Python 3.8 support was dropped in cchecksum v0.4.0. Users on Python 3.8 will need to use an older version of cchecksum (pre-0.4.0) or upgrade their Python interpreter to 3.9 or newer.
- gotcha To benefit from cchecksum's performance improvements, you must explicitly import `to_checksum_address` from `cchecksum`. If `eth_utils.to_checksum_address` remains in your code, you will continue to use the slower Python-based implementation.
- gotcha Installation may require a C compiler if pre-compiled wheels are not available for your specific Python version and operating system. The core logic is implemented in C and Cython.
Install
-
pip install cchecksum
Imports
- to_checksum_address
from eth_utils import to_checksum_address
from cchecksum import to_checksum_address
Quickstart
from cchecksum import to_checksum_address
from binascii import unhexlify
# Convert a lowercase hex string with 0x prefix
address_hex_lower = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"
checksummed_address = to_checksum_address(address_hex_lower)
print(f"Original: {address_hex_lower}")
print(f"Checksummed: {checksummed_address}")
# Convert bytes input (must be 20 bytes long)
address_bytes = unhexlify(address_hex_lower[2:]) # Removes '0x' prefix
checksummed_bytes_address = to_checksum_address(address_bytes)
print(f"Original Bytes: {address_bytes.hex()}")
print(f"Checksummed Bytes: {checksummed_bytes_address}")