Types

The following types are available from the eth_typing module.

i.e.

from eth_typing import TypeStr

Application Binary Interface

Types for Contract ABIs and related components.

eth_typing.abi.ABI

List of components representing function and event interfaces (elements of an ABI).

alias of Sequence[Union[ABIFunction, ABIConstructor, ABIFallback, ABIReceive, ABIEvent, ABIError]]

eth_typing.abi.ABICallable

A Union type consisting of ABIFunction, ABIConstructor, ABIFallback and ABIReceive types.

alias of Union[ABIFunction, ABIConstructor, ABIFallback, ABIReceive]

class eth_typing.abi.ABIComponent(*args, **kwargs)

TypedDict representing an ABIElement component.

components: typing_extensions.NotRequired[Sequence[ABIComponent]]

List of nested ABI components for ABI types.

name: str

Name of the component.

type: str

Type of the component.

class eth_typing.abi.ABIComponentIndexed(*args, **kwargs)

TypedDict representing an indexed ABIElement component.

components: typing_extensions.NotRequired[Sequence[ABIComponent]]
indexed: bool

If True, component can be used as a topic filter.

name: str
type: str
class eth_typing.abi.ABIConstructor(*args, **kwargs)

TypedDict representing the ABI for a constructor function.

constant: bool
inputs: typing_extensions.NotRequired[Sequence[ABIComponent]]

Function input components.

payable: bool
stateMutability: Literal['pure', 'view', 'nonpayable', 'payable']
type: Literal['constructor']

Type of the constructor function.

eth_typing.abi.ABIElement

A Union type consisting of ABICallable, ABIEvent, and ABIError types.

alias of Union[ABIFunction, ABIConstructor, ABIFallback, ABIReceive, ABIEvent, ABIError]

class eth_typing.abi.ABIElementInfo(*args, **kwargs)

TypedDict to represent properties of an ABIElement, including the abi, selector and arguments.

abi: ABIFunction | ABIConstructor | ABIFallback | ABIReceive | ABIEvent | ABIError

ABI for any ABIElement type.

arguments: Tuple[Any, ...]

ABIElement input components.

selector: HexStr

Solidity ABIElement selector sighash.

class eth_typing.abi.ABIError(*args, **kwargs)

TypedDict representing the ABI for an error.

inputs: typing_extensions.NotRequired[Sequence[ABIComponent]]

Error input components.

name: str

Name of the error.

type: Literal['error']

Type of the error.

class eth_typing.abi.ABIEvent(*args, **kwargs)

TypedDict to represent the ABI for an event.

anonymous: typing_extensions.NotRequired[bool]

If True, event is anonymous. Cannot filter the event by name.

inputs: typing_extensions.NotRequired[Sequence[ABIComponentIndexed]]

Input components for the event.

name: str

Event name identifier.

type: Literal['event']

Event ABI type.

class eth_typing.abi.ABIFallback(*args, **kwargs)

TypedDict representing the ABI for a fallback function.

constant: bool
payable: bool
stateMutability: Literal['pure', 'view', 'nonpayable', 'payable']
type: Literal['fallback']

Type of the fallback function.

class eth_typing.abi.ABIFunction(*args, **kwargs)

TypedDict representing the ABI for a function.

constant: bool
inputs: typing_extensions.NotRequired[Sequence[ABIComponent]]

Function input components.

name: str

Name of the function.

outputs: typing_extensions.NotRequired[Sequence[ABIComponent]]

Function output components.

payable: bool
stateMutability: Literal['pure', 'view', 'nonpayable', 'payable']
type: Literal['function']

Type of the function.

class eth_typing.abi.ABIFunctionType(*args, **kwargs)

TypedDict representing the ABI for all function types.

This is the base type for functions. Please use ABIFunction, ABIConstructor, ABIFallback or ABIReceive instead.

constant: bool

Function is constant and does not change state. Deprecated in favor of stateMutability pure and view.

payable: bool

Contract is payable to receive ether on deployment. Deprecated in favor of stateMutability payable and nonpayable.

stateMutability: Literal['pure', 'view', 'nonpayable', 'payable']

State mutability of the constructor.

class eth_typing.abi.ABIReceive(*args, **kwargs)

TypedDict representing the ABI for a receive function.

constant: bool
payable: bool
stateMutability: Literal['pure', 'view', 'nonpayable', 'payable']
type: Literal['receive']

Type of the receive function.

eth_typing.abi.Decodable

Binary data to be decoded.

alias of Union[bytes, bytearray]

eth_typing.abi.TypeStr

String representation of a data type.

BLS

Types used for BLS Signatures.

class eth_typing.bls.BLSPrivateKey

A BLS private key integer value.

alias of int

class eth_typing.bls.BLSPubkey

A BLS public key that is 48 bytes in length.

alias of bytes

class eth_typing.bls.BLSSignature

A BLS signature that is 96 bytes in length.

alias of bytes

Discovery

Types for the Discovery Protocol.

class eth_typing.discovery.NodeID

A 32-byte identifier for a node in the Discovery DHT.

>>> from eth_typing import NodeID
>>> NodeID(b'\x01' * 32)
b'\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01'

alias of bytes

Encoding

Types for encoding and decoding data.

class eth_typing.encoding.HexStr

A string that represents a hex encoded value.

alias of str

eth_typing.encoding.Primitives

A type that represents bytes, int or bool primitive types.

alias of Union[bytes, int, bool]

Enums

Fork names for Ethereum network upgrades.

class eth_typing.enums.ForkName

Constants for each fork name.

>>> from eth_typing import ForkName
>>> ForkName.Frontier
'Frontier'
ArrowGlacier = 'ArrowGlacier'
Berlin = 'Berlin'
Byzantium = 'Byzantium'
Cancun = 'Cancun'
Constantinople = 'Constantinople'
ConstantinopleFix = 'ConstantinopleFix'
EIP150 = 'EIP150'
EIP158 = 'EIP158'
Frontier = 'Frontier'
GrayGlacier = 'GrayGlacier'
Homestead = 'Homestead'
Istanbul = 'Istanbul'
London = 'London'
Metropolis = 'Metropolis'
Paris = 'Paris'
Shanghai = 'Shanghai'

EVM

Type definitions for the Ethereum Virtual Machine (EVM).

class eth_typing.evm.Address

A type that contains a 32-byte canonical address.

alias of bytes

class eth_typing.evm.AnyAddress

A type that represents any type of address.

alias of TypeVar(‘AnyAddress’, Address, HexAddress, ChecksumAddress)

eth_typing.evm.BlockIdentifier

A type that represents a block identifier value.

  • BlockParams: A block reference parameter.

  • BlockNumber: A block number integer value.

  • Hash32: A 32-byte hash value.

  • HexStr: A string that represents a hex value.

  • int: An integer value.

alias of Union[Literal[‘latest’, ‘earliest’, ‘pending’, ‘safe’, ‘finalized’], BlockNumber, Hash32, HexStr, int]

class eth_typing.evm.BlockNumber

Any integer that represents a valid block number on a chain.

alias of int

eth_typing.evm.BlockParams

A type which specifies the block reference parameter.

  • "latest": The latest block.

  • "earliest": The earliest block.

  • "pending": The pending block.

  • "safe": The safe block.

  • "finalized": The finalized block.

alias of Literal[‘latest’, ‘earliest’, ‘pending’, ‘safe’, ‘finalized’]

class eth_typing.evm.ChecksumAddress

A type that contains a eth_typing.evm.HexAddress that is formatted according to ERC55. This is a 40 character hex string with a prefix of “0x” and mixed case letters.

alias of HexAddress

class eth_typing.evm.Hash32

A 32-byte hash value.

alias of bytes

class eth_typing.evm.HexAddress

A type that contains a hex encoded address. This is a 32-byte hex string with a prefix of “0x”.

alias of HexStr

Exceptions

Exception types raised in web3’s libraries.

exception eth_typing.exceptions.MismatchedABI

Raised when an ABI does not match with supplied parameters, or when an attempt is made to access a function/event that does not exist in the ABI.

exception eth_typing.exceptions.ValidationError

Raised when something does not pass a validation check.

Networks

Types for Ethereum network identifiers.

class eth_typing.networks.ChainId(value)

IntEnum class defining EVM-compatible network name enums as their respective ChainID int values.

To learn more about chain ids, see CAIP-2 for details.

The list of chain ids is available from the ethereum-lists/chains repository.

For a complete list of supported enums, see eth_typing/networks.py.

>>> from eth_typing import ChainId
>>> ChainId(1)
<ChainId.ETH: 1>
>>> ChainId(10)
<ChainId.OETH: 10>
ETH = 1

Ethereum Mainnet

EXP = 2

Expanse

GNO = 100

Gnosis

GOR = 5

Görli

OETH = 10

OP Mainnet

RIN = 4

Rinkeby

ROP = 3

Ropsten

class eth_typing.networks.URI

Any string that represents a URI.

alias of str