Starknet Types#

Python representations of Starknet Types used in ABIs. Parsing functions convert ABI JSON into these Python types. Multiple versions of Cairo ABIs are parsed into the same format, ensuring seamless decoding and encoding across different versions, requiring only the ABI parsing logic to be updated for each new version.

class nethermind.starknet_abi.abi_types.StarknetCoreType#

Dataclasses representing the Core datatypes.

id_str()#

Returns the name of the enum field

>>> from nethermind.starknet_abi.abi_types import StarknetCoreType
>>> StarknetCoreType.U128.id_str()
'U128'
>>> StarknetCoreType.Bool.id_str()
'Bool'
>>> StarknetCoreType.ContractAddress.id_str()
'ContractAddress'
>>> StarknetCoreType.NoneType.id_str()
'NoneType'
>>> StarknetCoreType.StorageAddress.id_str()
'StorageAddress'
classmethod int_from_string(type_str)#

parses a core::integer::<type_str> into a Starknet Core type


Parameters:

type_str

max_value()#

Returns the maximum value of the Starknet Core Type

>>> from nethermind.starknet_abi.abi_types import StarknetCoreType
>>> StarknetCoreType.U256.max_value()
115792089237316195423570985008687907853269984665640564039457584007913129639935
class nethermind.starknet_abi.abi_types.StarknetArray#

Dataclass representing a Starknet ABI Array. Both core::array::Array and core::array::Span are mapped to this dataclass since their ABI Encoding & Decoding are identical

id_str()#
>>> from nethermind.starknet_abi.abi_types import StarknetArray, StarknetCoreType
>>> felt_array = StarknetArray(StarknetCoreType.Felt)
>>> felt_array.id_str()
'[Felt]'
class nethermind.starknet_abi.abi_types.StarknetOption#

Dataclass Representing a Starknet Option

id_str()#

Returns Inner Type String wrapped with Option[]

>>> from nethermind.starknet_abi.abi_types import StarknetOption, StarknetCoreType
>>> uint_option = StarknetOption(StarknetCoreType.U128)
>>> uint_option.id_str()
'Option[U128]'
class nethermind.starknet_abi.abi_types.StarknetTuple#

Dataclass Representing a Tuple, and the Types of the Tuple Members

id_str()#

Returns the string representation of a tuple of types


class nethermind.starknet_abi.abi_types.StarknetEnum#

Represents a StarknetEnum with its name and ordered variants

id_str()#

Returns Enum[<variant-name:variant-type>]

>>> from nethermind.starknet_abi.abi_types import StarknetEnum, StarknetCoreType
>>> status_enum = StarknetEnum(
...     name="Status",
...     variants=[
...         ('Success', StarknetCoreType.NoneType),
...         ('Failure', StarknetCoreType.NoneType),
...     ]
... )
>>> status_enum.id_str()
"Enum['Success','Failure']"
>>> type_enum = StarknetEnum(
...     name="AddressType",
...     variants=[
...         ('Class', StarknetCoreType.ClassHash),
...         ('Contract', StarknetCoreType.ContractAddress),
...     ]
... )
>>> type_enum.id_str()
'Enum[Class:ClassHash,Contract:ContractAddress]'
class nethermind.starknet_abi.abi_types.StarknetStruct#

Dataclass Representing a Starknet Struct Definition

id_str()#