ABI Types#
- class nethermind.starknet_abi.abi_types.AbiParameter#
Dataclass Representing an ABI Parameter. Includes a parameter name and the StarknetType of the parameter.
- id_str()#
Returns a string representation of the ABI Parameter. Represents the name, followed by a colon, then a type
>>> from nethermind.starknet_abi.abi_types import StarknetCoreType, AbiParameter >>> from_param = AbiParameter('from', StarknetCoreType.ContractAddress) >>> from_param.id_str() 'from:ContractAddress'
- class nethermind.starknet_abi.decoding_types.AbiFunction#
Dataclass Representing an ABI Function. Includes a function name, the function signature, and the input and output parameters.
- decode(calldata: list[int], result: list[int] | None = None) DecodedFunction #
Decode the calldata and result of a function.
>>> from nethermind.starknet_abi.decoding_types import AbiFunction >>> from nethermind.starknet_abi.abi_types import StarknetCoreType >>> add_function = AbiFunction( ... name="add", ... inputs=[AbiParameter("a", StarknetCoreType.U32), AbiParameter("b", StarknetCoreType.U32)], ... outputs=[StarknetCoreType.U64] ... ) >>> add_function.decode([123456, 654321], [777777]) DecodedFunction(abi_name=None, name='add', inputs={'a': 123456, 'b': 654321}, outputs=[777777])
- Parameters:
calldata –
result –
- encode(inputs: dict[str, Any]) list[int] #
Encode the inputs of a function into calldata.
>>> from nethermind.starknet_abi.decoding_types import AbiFunction >>> from nethermind.starknet_abi.abi_types import StarknetCoreType, StarknetArray >>> add_function = AbiFunction( ... name="add", ... inputs=[AbiParameter("add_vals", StarknetArray(StarknetCoreType.U8))], ... outputs=[StarknetCoreType.U128] ... ) >>> add_function.encode({"add_vals": [122, 212, 221]}) [3, 122, 212, 221]
- Parameters:
inputs – dict[function-param: value]
- Returns:
calldata array
- id_str()#
Returns a string representation of the ABI Function Types. Functions with identical types & parameter names will have an identical id_str()
>>> from nethermind.starknet_abi.decoding_types import AbiFunction >>> from nethermind.starknet_abi.abi_types import StarknetCoreType >>> add_function = AbiFunction( ... name="add", ... inputs=[AbiParameter("a", StarknetCoreType.U32), AbiParameter("b", StarknetCoreType.U32)], ... outputs=[StarknetCoreType.U64] ... ) >>> add_function.id_str() 'Function(a:U32,b:U32) -> (U64)'
- Returns:
Function(<parameters>) -> (<output-types>)
- class nethermind.starknet_abi.decoding_types.AbiEvent#
Dataclass representing an ABI Event. Includes an event name, the event signature, and the data parameters.
- decode(data: list[int], keys: list[int]) DecodedEvent #
Decode the keys and data of an event.
- Parameters:
data – Data array for decoding
keys – Optional data array of event keys
- Returns:
DecodedEvent
- id_str()#
Returns a string representation of the ABI Function.
>>> from nethermind.starknet_abi.decoding_types import AbiEvent >>> from nethermind.starknet_abi.abi_types import StarknetCoreType >>> add_event = AbiEvent( ... name="Create", ... parameters=["address"], ... data={"address": StarknetCoreType.ContractAddress}, ... ) >>> add_event.id_str() 'Event(address:ContractAddress)'
- Returns:
Event(<data keys>)
- class nethermind.starknet_abi.decoding_types.AbiInterface#
Dataclass Representing an ABI Interface. Includes a name and a list of functions.
- class nethermind.starknet_abi.decoding_types.DecodedFunction#
Dataclass representing the result of decoding an ABI
- class nethermind.starknet_abi.decoding_types.DecodedEvent#
Dataclass representing the result of decoding an ABI Event