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-abiVerified import paths — ran on the pinned version, not inferred.
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.
Upgrade Python to version 3.8 or higher, or pin `eth-abi<5.0.0`.
Upgrade Python to version 3.10 or higher when migrating to `eth-abi` v6.0.0.
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)`.
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.
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.
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.
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`.
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.
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.
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.