eth-utils

6.0.0 · active · verified Thu Apr 09

eth-utils provides a collection of common utility functions for Python code that interacts with Ethereum. It includes functionalities for ABI manipulation, address checksumming, type conversions, cryptographic hashing, and hexadecimal encoding/decoding. The library is currently at version 6.0.0 and maintains a frequent release cadence, often introducing minor and patch updates, with major versions released approximately annually.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates common utility functions like `to_checksum_address` for EIP-55 compliant addresses, `is_address` for validation, and `to_bytes` and `decode_hex` for handling various string and byte conversions, emphasizing the need for explicit type specification in conversions.

from eth_utils import to_checksum_address, is_address, to_bytes, decode_hex

# Example 1: Checksumming an Ethereum address
address_raw = '0xd3cda913deb6f67967b99d67acdfa1712c293601'
checksum_address = to_checksum_address(address_raw)
print(f"Raw address: {address_raw}")
print(f"Checksummed address: {checksum_address}")

# Example 2: Validating an address
is_valid = is_address(checksum_address)
print(f"Is '{checksum_address}' a valid address? {is_valid}")

# Example 3: Converting string to bytes, explicitly specifying type
hex_string = '0x123456'
bytes_data = to_bytes(hexstr=hex_string)
print(f"Hex string '{hex_string}' to bytes: {bytes_data}")

# Example 4: Decoding a hexadecimal string to bytes
decoded_bytes = decode_hex('0xabcdef')
print(f"Decoded '0xabcdef' to bytes: {decoded_bytes}")

view raw JSON →