faster-eth-abi
raw JSON → 5.2.27 verified Mon Apr 27 auth: no python
A ~2-6x faster fork of eth_abi: Python utilities for encoding and decoding Ethereum ABI definitions, implemented in C for performance. Current stable version: 5.2.27. Requires Python >=3.10, <4. Released on a continuous cadence.
pip install faster-eth-abi Common errors
error AttributeError: module 'faster_eth_abi' has no attribute 'decode_single' ↓
cause Version mismatch or incomplete installation. Older versions (pre-5.0) used a different API.
fix
Upgrade to latest version:
pip install --upgrade faster-eth-abi. Ensure Python >=3.10. error TypeError: Encoding 'str' to 'address' is not supported ↓
cause Addresses must be bytes (20 bytes) or hex strings with '0x' prefix. Passing a plain string (e.g., '0x...') without bytes conversion works if it's a valid hex, but a Python str that isn't a hex address fails.
fix
Use
bytes.fromhex(address[2:]) or ensure address is a bytes-like object. Example: encode_single('address', bytes.fromhex('1234...')). error ValueError: The value provided must be an even-length string. ↓
cause Hex string has odd number of characters (e.g., '0x123').
fix
Pad hex string with a leading zero: '0x0123'.
Warnings
gotcha faster-eth-abi is a fork of eth_abi but they are separate packages. Installing faster-eth-abi does not replace eth_abi; if your code imports from eth_abi, you will not see performance gains. ↓
fix Replace all imports of form `from eth_abi import ...` with `from faster_eth_abi import ...`. Also update dependencies to require faster-eth-abi instead of eth-abi.
breaking Version 5.0.0 introduced breaking changes: removed support for Python 3.7 and 3.8, and changed internal module structure. Code relying on private modules may break. ↓
fix Upgrade Python to 3.9+ (now 3.10+). Use only public API: `from faster_eth_abi import encode_single, decode_single, encode_abi, decode_abi`.
deprecated The function `decode_abi` with positional arguments has been deprecated in favor of keyword argument style. In older versions: `decode_abi(types, data)`; now recommend `decode_abi(types, data)` still works but future versions may change. ↓
fix Use keyword arguments: `decode_abi(types=types, data=data)`.
gotcha When encoding arrays, the type string must match exactly (e.g., 'uint256[]' not 'uint256[1]' for dynamic arrays). Using an incorrect type may produce silent data corruption. ↓
fix Ensure array types are correctly specified: dynamic arrays use '[]', static use '[size]'. Validate with decode_abi after encoding.
Imports
- decode_single wrong
from eth_abi import decode_singlecorrectfrom faster_eth_abi import decode_single - encode_single wrong
from eth_abi import encode_singlecorrectfrom faster_eth_abi import encode_single
Quickstart
from faster_eth_abi import encode_single, decode_single
# Encode a uint256 value
encoded = encode_single('uint256', 42)
print(encoded.hex()) # e.g., '000000000000000000000000000000000000000000000000000000000000002a'
# Decode back
decoded = decode_single('uint256', encoded)
print(decoded) # 42
# Encode a tuple
from faster_eth_abi import encode_abi
types = ['address', 'uint256']
values = ['0x1234567890abcdef1234567890abcdef12345678', 100]
encoded = encode_abi(types, values)
print(encoded.hex())