Registry / serialization / eth-abi

eth-abi

JSON →
library6.0.0pypypi✓ verified 26d ago

The `eth-abi` library, currently at version 5.2.0, provides low-level Python utilities for converting Python values to and from Solidity's binary Application Binary Interface (ABI) format. It is a core component within the Ethereum development ecosystem, offering functionalities for encoding Python values into ABI-compliant bytes and decoding ABI bytes back into Python values for smart contract interaction. The library maintains an active release cadence with frequent updates, including bug fixes, new features, and Python version support, with major versions typically released annually or biannually.

pip install eth-abi
INSTALL
IMPORT
SIG · ETH-ABI
E
eth-abi
serializationpythonv6.0.0
Install
4.6s avg
Import
834ms
Disk
43MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v6.0.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.864s · 43.4MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 4.6s · import 0.804s · 46MB
43MB installed
● package 43MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

encode
from eth_abi import encode
Main function for encoding Python values into ABI bytes.
decode
from eth_abi import decode
Main function for decoding ABI bytes into Python values.
registry
from eth_abi import registry
Used for customizing encoding/decoding behavior for ABI types.

This quickstart demonstrates the core functionality of `eth-abi`: encoding a list of Python values (integers, addresses, booleans, strings) into a single ABI-compliant `bytes` object, and then decoding that `bytes` object back into a tuple of Python values. It also shows a simple `uint256` encoding/decoding example.

from eth_abi import encode, decode # Define ABI types and corresponding Python values abi_types = ['uint256', 'address', 'bool', 'string'] python_values = [123, '0x5B38Da6a701c568545dCfcB03FcB875f56beddC4', True, 'Hello eth-abi'] # Encode Python values into ABI-compliant bytes encoded_data = encode(abi_types, python_values) print(f"Encoded data: {encoded_data.hex()}") # Decode ABI-compliant bytes back into Python values decoded_values = decode(abi_types, encoded_data) print(f"Decoded values: {decoded_values}") # Example with a simple uint256 encoded_uint = encode(['uint256'], [1]) decoded_uint = decode(['uint256'], b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01') print(f"Decoded single uint: {decoded_uint}")
Debug
Known issues
breakingVersion 5.0.0 of `eth-abi` dropped support for Python 3.7. Users on older Python versions will need to upgrade their environment or stick to `eth-abi` versions < 5.0.0.
fix
Upgrade Python to version 3.8 or higher, or pin `eth-abi<5.0.0`.
affects: >=5.0.0
breakingUpcoming version 6.0.0 (currently in beta) will drop support for Python 3.8 and 3.9. Plan for future Python environment upgrades if targeting this version.
fix
Upgrade Python to version 3.10 or higher when migrating to `eth-abi` v6.0.0.
affects: >=6.0.0 (beta)
gotchaThe `decode` function defaults to `strict=True`, which performs validations such as ensuring data is padded to a multiple of 32 bytes and that padding bytes are zero. However, Solidity's ABI decoder operates with a behavior equivalent to `strict=False`, which ignores some of these validations. This difference can lead to unexpected errors if not handled, particularly when decoding data from contracts that might not adhere strictly to padding rules.
fix
When decoding data from smart contracts, consider setting `strict=False` in the `decode` function if encountering padding or zero-byte validation errors, as this often aligns with how Solidity handles ABI decoding. Example: `decode(abi_types, encoded_data, strict=False)`.
affects: All versions
gotchaUnderstanding the Ethereum ABI specification is crucial for correctly using `eth-abi`. Complex types (like dynamic arrays, strings, and tuples) have specific encoding rules, including how their data is positioned (head/tail mechanism) and padded to 32-byte boundaries. Misunderstanding these rules can lead to incorrect encoding or decoding.
fix
Refer to the official Solidity ABI specification and `eth-abi` documentation for detailed explanations of type encoding and decoding rules, especially for dynamic and nested types.
affects: All versions
gotchaContract ABIs (Application Binary Interfaces) are not stored on the blockchain itself. To interact with a smart contract using `eth-abi` (or any web3 library), you need to obtain the contract's ABI from external sources. Common sources include block explorers (like Etherscan for verified contracts), the contract's official GitHub repository, or by compiling the contract's source code yourself.
fix
Always ensure you have the correct and complete ABI for the target smart contract. If an ABI is unavailable or incorrect, interactions with the contract will fail or yield erroneous results.
affects: All versions
Errors
Common errors & fixes
eth_abi.exceptions.EncodingTypeError: Unsupported type
The Python value provided for encoding does not have a corresponding or compatible ABI type registered in `eth-abi`, often due to a mismatch between Python's native types and Solidity's ABI types (e.g., using a string for a `uint256`).
fix
Ensure the Python data type precisely matches the expected ABI type; for instance, use `int` for `uint` or `address` types, `bytes` for `bytesN` types, and `str` for `string` types.
eth_abi.exceptions.ValueOutOfBounds: value too large for uint256
The numeric Python value provided for encoding exceeds the maximum or falls below the minimum allowed range for the specified Solidity integer or fixed-point ABI type.
fix
Adjust the Python value to fit within the valid range of the target ABI type; for unsigned integers (e.g., `uintX`), the value must be non-negative and less than `2**X`.
eth_abi.exceptions.ABITypeError: Parsed ABI type has inconsistent properties: uint7
The provided ABI type string is syntactically incorrect or specifies properties invalid for a Solidity ABI type, such as `uint7` where `uint` bit widths must be multiples of 8.
fix
Correct the ABI type string according to Solidity's ABI specification; for `uint` and `int` types, bit sizes must be a multiple of 8 (from 8 to 256), and for `bytesN`, `N` must be between 1 and 32.
eth_abi.exceptions.InsufficientDataBytes: insufficient data for `type`
The input `bytes` stream provided for decoding does not contain enough data to fully decode the specified ABI type(s), possibly due to truncated or malformed input data.
fix
Verify that the input `bytes` data is complete and correctly formed, ensuring it matches the expected ABI encoding for the given types and that all dynamic data pointers and lengths are valid.
Error encoding arguments: Error: types/values length mismatch (count={"types":X,"values":Y})
The number of ABI types provided for encoding does not match the number of corresponding Python values, or there is an inconsistency within complex types like tuples or arrays where element counts do not align.
fix
Ensure that the list of ABI type strings and the list of corresponding Python values have identical lengths, and that all nested types (e.g., tuples, arrays) have their elements correctly matched.
Upgrade
Version history
6.0.0latest on PyPI · released Aug 22, 2026
Audit
Dependencies
eth-typingrequiredRequired for Ethereum type definitions.
eth-utilsrequiredRequired for Ethereum utility functions.
parsimoniousrequiredUsed for parsing ABI type strings.
Agent activity
9 hits · last 30 days
node
8
Resources
eth-abi — pip install eth-abi · libregistry