eth-abi

5.2.0 · active · verified Thu Apr 09

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.

Warnings

Install

Imports

Quickstart

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}")

view raw JSON →