ape.contracts
- class ape.contracts.base.ContractTypeWrapper
Bases:
ManagerAccessMixin
- decode_input(calldata: bytes) tuple[str, dict[str, Any]]
Decode the given calldata using this contract. If the calldata has a method ID prefix, Ape will detect it and find the corresponding method, else it will error.
- Parameters:
calldata (bytes) – The calldata to decode.
- Returns:
A tuple containing the method selector along a mapping of input names to their decoded values. If an input does not have a number, it will have the stringified index as its key.
- Return type:
tuple[str, dict[str, Any]]
- property identifier_lookup: dict[str, ConstructorABI | MethodABI | EventABI | StructABI | ErrorABI]
Provides a mapping of method, error, and event selector identifiers to ABI Types.
- property selector_identifiers: dict[str, str]
Provides a mapping of function signatures (pre-hashed selectors) to selector identifiers.
- property source_path: Path | None
Returns the path to the local contract if determined that this container belongs to the active project by cross checking source_id.
- class ape.contracts.base.ContractInstance(address: Annotated[ChecksumAddress, _AddressValidator], contract_type: ContractType, txn_hash: str | HexBytes | None = None)
Bases:
BaseAddress
,ContractTypeWrapper
An interactive instance of a smart contract. After you deploy a contract using the
deploy
method, you get back a contract instance.Usage example:
from ape import accounts, project a = accounts.load("alias") # Load an account by alias contract = a.deploy(project.MyContract) # The result of 'deploy()' is a ContractInstance
- __call__(*args, **kwargs) ReceiptAPI
Call this address directly. For contracts, this may mean invoking their default handler.
- Parameters:
**kwargs – Transaction arguments, such as
sender
ordata
.- Returns:
- __repr__() str
Return repr(self).
- property address: Annotated[ChecksumAddress, _AddressValidator]
The address of the contract.
- Returns:
- call_view_method(method_name: str, *args, **kwargs) Any
Call a contract’s view function directly using the method_name. This is helpful in the scenario where the contract has a method name matching an attribute of the
BaseAddress
class, such asnonce
orbalance
- Parameters:
method_name (str) – The contract method name to be called
*args – Contract method arguments.
**kwargs – Transaction values, such as
value
orsender
- Returns:
Output of smart contract view call.
- Return type:
Any
- property creation_metadata: ContractCreation | None
txn_hash, block, deployer, factory, receipt. See
ContractCreation
for more details. NOTE: Must be either connected to a node that provides this data, such as a node with theots_
namespace enabled, or have a query-plugin installed that can fetch this data, such asape-etherscan
.- Type:
Contract creation details
- classmethod from_receipt(receipt: ReceiptAPI, contract_type: ContractType) ContractInstance
Create a contract instance from the contract deployment receipt.
- get_error_by_signature(signature: str) type[CustomError]
Get an error by its signature, similar to
get_event_by_signature()
.- Parameters:
signature (str) – The signature of the error.
- Returns:
- get_event_by_signature(signature: str) ContractEvent
Get an event by its signature. Most often, you can use the
__getattr__()
method on this class to access events. However, in the case when you have more than one event with the same name, such as the case where one event is coming from a base contract, you can use this method to access the respective events.- Parameters:
signature (str) – The signature of the event.
- Returns:
- invoke_transaction(method_name: str, *args, **kwargs) ReceiptAPI
Call a contract’s function directly using the method_name. This function is for non-view function’s which may change contract state and will execute a transaction. This is helpful in the scenario where the contract has a method name matching an attribute of the
BaseAddress
class, such asnonce
orbalance
- Parameters:
method_name (str) – The contract method name to be called
*args – Contract method arguments.
**kwargs – Transaction values, such as
value
orsender
- Returns:
Output of smart contract interaction.
- Return type:
- class ape.contracts.base.ContractContainer(contract_type: ContractType)
Bases:
ContractTypeWrapper
,ExtraAttributesMixin
A wrapper around the contract type that has access to the provider. When you import your contracts from the
ape.managers.project.ProjectManager
, you are using this class.Usage example:
from ape import project contract_container = project.MyContract # Assuming there is a contract named "MyContract"
- __call__(*args, **kwargs) TransactionAPI
Call self as a function.
- __eq__(other)
Return self==value.
- __hash__ = None
- __repr__() str
Return repr(self).
- at(address: Annotated[ChecksumAddress, _AddressValidator], txn_hash: str | HexBytes | None = None) ContractInstance
Get a contract at the given address.
Usage example:
from ape import project my_contract = project.MyContract.at("0xAbC1230001112223334445566611855443322111")
- Parameters:
address (str) – The address to initialize a contract. NOTE: Things will not work as expected if the contract is not actually deployed to this address or if the contract at the given address has a different ABI than
contract_type
.txn_hash (Union[str, HexBytes]) – The hash of the transaction that deployed the contract, if available. Defaults to
None
.
- Returns:
ContractInstance
- deploy(*args, publish: bool = False, **kwargs) ContractInstance
Deploy a contract.
- Parameters:
*args (Any) – The contract’s constructor arguments as Python types.
publish (bool) – Whether to also perform contract-verification. Defaults to
False
.
- Returns:
- property deployments
Contract deployments.
Usage example:
# Get the latest deployment my_contract = project.MyContract.deployments[-1]
- class ape.contracts.base.ContractEvent
Bases:
BaseInterfaceModel
The types of events on a
ContractInstance
. Use the event types via.
access on the contract instances.Usage example:
# 'my_contract' refers to a ContractInstance in this case. my_event_type = my_contract.MyEvent
- __call__(*args: Any, **kwargs: Any) MockContractLog
Call self as a function.
- __class_vars__: ClassVar[set[str]] = {'Project', '_test_runner', 'account_manager', 'chain_manager', 'compiler_manager', 'config_manager', 'conversion_manager', 'local_project', 'network_manager', 'plugin_manager', 'query_manager'}
The names of the class variables defined on the model.
- __iter__() Iterator[ContractLog]
Get all logs that have occurred for this event.
- __private_attributes__: ClassVar[Dict[str, ModelPrivateAttr]] = {'_logs': ModelPrivateAttr()}
Metadata about the private attributes of the model.
- __pydantic_complete__: ClassVar[bool] = True
Whether model building is completed, or if there are still undefined fields.
- __pydantic_core_schema__: ClassVar[CoreSchema] = {'definitions': [{'cls': <class 'ethpm_types.abi.ABIType'>, 'config': {'extra_fields_behavior': 'allow', 'title': 'ABIType'}, 'custom_init': False, 'metadata': {'pydantic_js_annotation_functions': [], 'pydantic_js_functions': [functools.partial(<function modify_model_json_schema>, cls=<class 'ethpm_types.abi.ABIType'>, title=None), <bound method BaseModel.__get_pydantic_json_schema__ of <class 'ethpm_types.abi.ABIType'>>]}, 'ref': 'ethpm_types.abi.ABIType:94763126179280', 'root_model': False, 'schema': {'computed_fields': [], 'fields': {'components': {'metadata': {'pydantic_js_annotation_functions': [<function get_json_schema_update_func.<locals>.json_schema_update_func>], 'pydantic_js_functions': []}, 'schema': {'default': None, 'schema': {'schema': {'items_schema': {'schema_ref': 'ethpm_types.abi.ABIType:94763126179280', 'type': 'definition-ref'}, 'type': 'list'}, 'type': 'nullable'}, 'type': 'default'}, 'type': 'model-field'}, 'internal_type': {'metadata': {'pydantic_js_annotation_functions': [<function get_json_schema_update_func.<locals>.json_schema_update_func>], 'pydantic_js_functions': []}, 'schema': {'default': None, 'schema': {'schema': {'type': 'str'}, 'type': 'nullable'}, 'type': 'default'}, 'serialization_alias': 'internalType', 'type': 'model-field', 'validation_alias': 'internalType'}, 'name': {'metadata': {'pydantic_js_annotation_functions': [<function get_json_schema_update_func.<locals>.json_schema_update_func>], 'pydantic_js_functions': []}, 'schema': {'default': None, 'schema': {'schema': {'type': 'str'}, 'type': 'nullable'}, 'type': 'default'}, 'type': 'model-field'}, 'type': {'metadata': {'pydantic_js_annotation_functions': [<function get_json_schema_update_func.<locals>.json_schema_update_func>], 'pydantic_js_functions': []}, 'schema': {'choices': [{'type': 'str'}, {'schema_ref': 'ethpm_types.abi.ABIType:94763126179280', 'type': 'definition-ref'}], 'type': 'union'}, 'type': 'model-field'}}, 'model_name': 'ABIType', 'type': 'model-fields'}, 'type': 'model'}], 'schema': {'cls': <class 'ape.contracts.base.ContractEvent'>, 'config': {'title': 'ContractEvent'}, 'custom_init': True, 'metadata': {'pydantic_js_annotation_functions': [], 'pydantic_js_functions': [functools.partial(<function modify_model_json_schema>, cls=<class 'ape.contracts.base.ContractEvent'>, title=None), <bound method BaseModel.__get_pydantic_json_schema__ of <class 'ape.contracts.base.ContractEvent'>>]}, 'post_init': 'model_post_init', 'ref': 'ape.contracts.base.ContractEvent:94763158005008', 'root_model': False, 'schema': {'computed_fields': [], 'fields': {'abi': {'metadata': {'pydantic_js_annotation_functions': [<function get_json_schema_update_func.<locals>.json_schema_update_func>], 'pydantic_js_functions': []}, 'schema': {'cls': <class 'ethpm_types.abi.EventABI'>, 'config': {'title': 'EventABI'}, 'custom_init': False, 'metadata': {'pydantic_js_annotation_functions': [], 'pydantic_js_functions': [functools.partial(<function modify_model_json_schema>, cls=<class 'ethpm_types.abi.EventABI'>, title=None), <bound method BaseModel.__get_pydantic_json_schema__ of <class 'ethpm_types.abi.EventABI'>>]}, 'ref': 'ethpm_types.abi.EventABI:94763124174096', 'root_model': False, 'schema': {'computed_fields': [], 'fields': {'anonymous': {'metadata': {'pydantic_js_annotation_functions': [<function get_json_schema_update_func.<locals>.json_schema_update_func>], 'pydantic_js_functions': []}, 'schema': {'default': False, 'schema': {'type': 'bool'}, 'type': 'default'}, 'type': 'model-field'}, 'inputs': {'metadata': {'pydantic_js_annotation_functions': [<function get_json_schema_update_func.<locals>.json_schema_update_func>], 'pydantic_js_functions': []}, 'schema': {'default': [], 'schema': {'items_schema': {'cls': <class 'ethpm_types.abi.EventABIType'>, 'config': {'extra_fields_behavior': 'allow', 'title': 'EventABIType'}, 'custom_init': False, 'metadata': {'pydantic_js_annotation_functions': [], 'pydantic_js_functions': [functools.partial(<function modify_model_json_schema>, cls=<class 'ethpm_types.abi.EventABIType'>, title=None), <bound method BaseModel.__get_pydantic_json_schema__ of <class 'ethpm_types.abi.EventABIType'>>]}, 'ref': 'ethpm_types.abi.EventABIType:94763124086464', 'root_model': False, 'schema': {'computed_fields': [], 'fields': {'components': {'metadata': {'pydantic_js_annotation_functions': [<function get_json_schema_update_func.<locals>.json_schema_update_func>], 'pydantic_js_functions': []}, 'schema': {'default': None, 'schema': {'schema': {'items_schema': {'schema_ref': 'ethpm_types.abi.ABIType:94763126179280', 'type': 'definition-ref'}, 'type': 'list'}, 'type': 'nullable'}, 'type': 'default'}, 'type': 'model-field'}, 'indexed': {'metadata': {'pydantic_js_annotation_functions': [<function get_json_schema_update_func.<locals>.json_schema_update_func>], 'pydantic_js_functions': []}, 'schema': {'default': False, 'schema': {'type': 'bool'}, 'type': 'default'}, 'type': 'model-field'}, 'internal_type': {'metadata': {'pydantic_js_annotation_functions': [<function get_json_schema_update_func.<locals>.json_schema_update_func>], 'pydantic_js_functions': []}, 'schema': {'default': None, 'schema': {'schema': {'type': 'str'}, 'type': 'nullable'}, 'type': 'default'}, 'serialization_alias': 'internalType', 'type': 'model-field', 'validation_alias': 'internalType'}, 'name': {'metadata': {'pydantic_js_annotation_functions': [<function get_json_schema_update_func.<locals>.json_schema_update_func>], 'pydantic_js_functions': []}, 'schema': {'default': None, 'schema': {'schema': {'type': 'str'}, 'type': 'nullable'}, 'type': 'default'}, 'type': 'model-field'}, 'type': {'metadata': {'pydantic_js_annotation_functions': [<function get_json_schema_update_func.<locals>.json_schema_update_func>], 'pydantic_js_functions': []}, 'schema': {'choices': [{'type': 'str'}, {'schema_ref': 'ethpm_types.abi.ABIType:94763126179280', 'type': 'definition-ref'}], 'type': 'union'}, 'type': 'model-field'}}, 'model_name': 'EventABIType', 'type': 'model-fields'}, 'type': 'model'}, 'type': 'list'}, 'type': 'default'}, 'type': 'model-field'}, 'name': {'metadata': {'pydantic_js_annotation_functions': [<function get_json_schema_update_func.<locals>.json_schema_update_func>], 'pydantic_js_functions': []}, 'schema': {'type': 'str'}, 'type': 'model-field'}, 'type': {'metadata': {'pydantic_js_annotation_functions': [<function get_json_schema_update_func.<locals>.json_schema_update_func>], 'pydantic_js_functions': []}, 'schema': {'default': 'event', 'schema': {'expected': ['event'], 'type': 'literal'}, 'type': 'default'}, 'type': 'model-field'}}, 'model_name': 'EventABI', 'type': 'model-fields'}, 'type': 'model'}, 'type': 'model-field'}, 'contract': {'metadata': {'pydantic_js_annotation_functions': [<function get_json_schema_update_func.<locals>.json_schema_update_func>], 'pydantic_js_functions': []}, 'schema': {'cls': <class 'ape.contracts.base.ContractTypeWrapper'>, 'type': 'is-instance'}, 'type': 'model-field'}}, 'model_name': 'ContractEvent', 'type': 'model-fields'}, 'type': 'model'}, 'type': 'definitions'}
The core schema of the model.
- __pydantic_custom_init__: ClassVar[bool] = True
Whether the model has a custom __init__ method.
- __pydantic_decorators__: ClassVar[_decorators.DecoratorInfos] = DecoratorInfos(validators={}, field_validators={}, root_validators={}, field_serializers={}, model_serializers={}, model_validators={}, computed_fields={})
Metadata containing the decorators defined on the model. This replaces Model.__validators__ and Model.__root_validators__ from Pydantic V1.
- __pydantic_generic_metadata__: ClassVar[_generics.PydanticGenericMetadata] = {'args': (), 'origin': None, 'parameters': ()}
Metadata for generic models; contains data used for a similar purpose to __args__, __origin__, __parameters__ in typing-module generics. May eventually be replaced by these.
- __pydantic_parent_namespace__: ClassVar[Dict[str, Any] | None] = {'subject': <pydantic._internal._mock_val_ser.MockValSer object>}
Parent namespace of the model, used for automatic rebuilding of models.
- __pydantic_post_init__: ClassVar[None | Literal['model_post_init']] = 'model_post_init'
The name of the post-init method for the model, if defined.
- __pydantic_serializer__: ClassVar[SchemaSerializer] = SchemaSerializer(serializer=Model( ModelSerializer { class: Py( 0x0000562fc45ee510, ), serializer: Fields( GeneralFieldsSerializer { fields: { "abi": SerField { key_py: Py( 0x00007ff1dcd92130, ), alias: None, alias_py: None, serializer: Some( Model( ModelSerializer { class: Py( 0x0000562fc25aad10, ), serializer: Fields( GeneralFieldsSerializer { fields: { "anonymous": SerField { key_py: Py( 0x00007ff1de9cd230, ), alias: None, alias_py: None, serializer: Some( WithDefault( WithDefaultSerializer { default: Default( Py( 0x00007ff1dfb63c80, ), ), serializer: Bool( BoolSerializer, ), }, ), ), required: true, }, "inputs": SerField { key_py: Py( 0x00007ff1dcc646b0, ), alias: None, alias_py: None, serializer: Some( WithDefault( WithDefaultSerializer { default: Default( Py( 0x00007ff1db7282c0, ), ), serializer: List( ListSerializer { item_serializer: Model( ModelSerializer { class: Py( 0x0000562fc25956c0, ), serializer: Fields( GeneralFieldsSerializer { fields: { "name": SerField { key_py: Py( 0x00007ff1df754af0, ), alias: None, alias_py: None, serializer: Some( WithDefault( WithDefaultSerializer { default: Default( Py( 0x00007ff1dfb78940, ), ), serializer: Nullable( NullableSerializer { serializer: Str( StrSerializer, ), }, ), }, ), ), required: true, }, "type": SerField { key_py: Py( 0x00007ff1df754d70, ), alias: None, alias_py: None, serializer: Some( Union( UnionSerializer { choices: [ Str( StrSerializer, ), Recursive( DefinitionRefSerializer { definition: "...", retry_with_lax_check: true, }, ), ], name: "Union[str, definition-ref]", }, ), ), required: true, }, "internal_type": SerField { key_py: Py( 0x00007ff1dca0ac70, ), alias: Some( "internalType", ), alias_py: Some( Py( 0x00007ff1c3f014b0, ), ), serializer: Some( WithDefault( WithDefaultSerializer { default: Default( Py( 0x00007ff1dfb78940, ), ), serializer: Nullable( NullableSerializer { serializer: Str( StrSerializer, ), }, ), }, ), ), required: true, }, "indexed": SerField { key_py: Py( 0x00007ff1dca0b9f0, ), alias: None, alias_py: None, serializer: Some( WithDefault( WithDefaultSerializer { default: Default( Py( 0x00007ff1dfb63c80, ), ), serializer: Bool( BoolSerializer, ), }, ), ), required: true, }, "components": SerField { key_py: Py( 0x00007ff1dedd95b0, ), alias: None, alias_py: None, serializer: Some( WithDefault( WithDefaultSerializer { default: Default( Py( 0x00007ff1dfb78940, ), ), serializer: Nullable( NullableSerializer { serializer: List( ListSerializer { item_serializer: Recursive( DefinitionRefSerializer { definition: "...", retry_with_lax_check: true, }, ), filter: SchemaFilter { include: None, exclude: None, }, name: "list[definition-ref]", }, ), }, ), }, ), ), required: true, }, }, computed_fields: Some( ComputedFields( [], ), ), mode: ModelExtra, extra_serializer: None, filter: SchemaFilter { include: None, exclude: None, }, required_fields: 5, }, ), has_extra: true, root_model: false, name: "EventABIType", }, ), filter: SchemaFilter { include: None, exclude: None, }, name: "list[EventABIType]", }, ), }, ), ), required: true, }, "name": SerField { key_py: Py( 0x00007ff1df754af0, ), alias: None, alias_py: None, serializer: Some( Str( StrSerializer, ), ), required: true, }, "type": SerField { key_py: Py( 0x00007ff1df754d70, ), alias: None, alias_py: None, serializer: Some( WithDefault( WithDefaultSerializer { default: Default( Py( 0x00007ff1defaabf0, ), ), serializer: Literal( LiteralSerializer { expected_int: {}, expected_str: { "event", }, expected_py: None, name: "literal['event']", }, ), }, ), ), required: true, }, }, computed_fields: Some( ComputedFields( [], ), ), mode: SimpleDict, extra_serializer: None, filter: SchemaFilter { include: None, exclude: None, }, required_fields: 4, }, ), has_extra: false, root_model: false, name: "EventABI", }, ), ), required: true, }, "contract": SerField { key_py: Py( 0x00007ff1ddf9de70, ), alias: None, alias_py: None, serializer: Some( Any( AnySerializer, ), ), required: true, }, }, computed_fields: Some( ComputedFields( [], ), ), mode: SimpleDict, extra_serializer: None, filter: SchemaFilter { include: None, exclude: None, }, required_fields: 2, }, ), has_extra: false, root_model: false, name: "ContractEvent", }, ), definitions=[Model(ModelSerializer { class: Py(0x562fc27945d0), serializer: Fields(GeneralFieldsSerializer { fields: {"type": SerField { key_py: Py(0x7ff1df754d70), alias: None, alias_py: None, serializer: Some(Union(UnionSerializer { choices: [Str(StrSerializer), Recursive(DefinitionRefSerializer { definition: "...", retry_with_lax_check: true })], name: "Union[str, definition-ref]" })), required: true }, "components": SerField { key_py: Py(0x7ff1dedd95b0), alias: None, alias_py: None, serializer: Some(WithDefault(WithDefaultSerializer { default: Default(Py(0x7ff1dfb78940)), serializer: Nullable(NullableSerializer { serializer: List(ListSerializer { item_serializer: Recursive(DefinitionRefSerializer { definition: "...", retry_with_lax_check: true }), filter: SchemaFilter { include: None, exclude: None }, name: "list[definition-ref]" }) }) })), required: true }, "internal_type": SerField { key_py: Py(0x7ff1dca0ac70), alias: Some("internalType"), alias_py: Some(Py(0x7ff1c87a08b0)), serializer: Some(WithDefault(WithDefaultSerializer { default: Default(Py(0x7ff1dfb78940)), serializer: Nullable(NullableSerializer { serializer: Str(StrSerializer) }) })), required: true }, "name": SerField { key_py: Py(0x7ff1df754af0), alias: None, alias_py: None, serializer: Some(WithDefault(WithDefaultSerializer { default: Default(Py(0x7ff1dfb78940)), serializer: Nullable(NullableSerializer { serializer: Str(StrSerializer) }) })), required: true }}, computed_fields: Some(ComputedFields([])), mode: ModelExtra, extra_serializer: None, filter: SchemaFilter { include: None, exclude: None }, required_fields: 4 }), has_extra: true, root_model: false, name: "ABIType" })])
The pydantic-core SchemaSerializer used to dump instances of the model.
- __pydantic_validator__: ClassVar[SchemaValidator | PluggableSchemaValidator] = SchemaValidator(title="ContractEvent", validator=Model( ModelValidator { revalidate: Never, validator: ModelFields( ModelFieldsValidator { fields: [ Field { name: "contract", lookup_key: Simple { key: "contract", py_key: Py( 0x00007ff1c40d55f0, ), path: LookupPath( [ S( "contract", Py( 0x00007ff1c40d5530, ), ), ], ), }, name_py: Py( 0x00007ff1ddf9de70, ), validator: IsInstance( IsInstanceValidator { class: Py( 0x0000562fc45edc50, ), class_repr: "ContractTypeWrapper", name: "is-instance[ContractTypeWrapper]", }, ), frozen: false, }, Field { name: "abi", lookup_key: Simple { key: "abi", py_key: Py( 0x00007ff1c3f00530, ), path: LookupPath( [ S( "abi", Py( 0x00007ff1c3f03af0, ), ), ], ), }, name_py: Py( 0x00007ff1dcd92130, ), validator: Model( ModelValidator { revalidate: Never, validator: ModelFields( ModelFieldsValidator { fields: [ Field { name: "type", lookup_key: Simple { key: "type", py_key: Py( 0x00007ff1c40d4770, ), path: LookupPath( [ S( "type", Py( 0x00007ff1c40d7830, ), ), ], ), }, name_py: Py( 0x00007ff1df754d70, ), validator: WithDefault( WithDefaultValidator { default: Default( Py( 0x00007ff1defaabf0, ), ), on_error: Raise, validator: Literal( LiteralValidator { lookup: LiteralLookup { expected_bool: None, expected_int: None, expected_str: Some( { "event": 0, }, ), expected_py_dict: None, expected_py_values: None, values: [ Py( 0x00007ff1defaabf0, ), ], }, expected_repr: "'event'", name: "literal['event']", }, ), validate_default: false, copy_default: false, name: "default[literal['event']]", undefined: Py( 0x00007ff1dc854dc0, ), }, ), frozen: false, }, Field { name: "name", lookup_key: Simple { key: "name", py_key: Py( 0x00007ff1c40d4df0, ), path: LookupPath( [ S( "name", Py( 0x00007ff1c40d77f0, ), ), ], ), }, name_py: Py( 0x00007ff1df754af0, ), validator: Str( StrValidator { strict: false, coerce_numbers_to_str: false, }, ), frozen: false, }, Field { name: "inputs", lookup_key: Simple { key: "inputs", py_key: Py( 0x00007ff1c3f0d730, ), path: LookupPath( [ S( "inputs", Py( 0x00007ff1c3f0e970, ), ), ], ), }, name_py: Py( 0x00007ff1dcc646b0, ), validator: WithDefault( WithDefaultValidator { default: Default( Py( 0x00007ff1db7282c0, ), ), on_error: Raise, validator: List( ListValidator { strict: false, item_validator: Some( Model( ModelValidator { revalidate: Never, validator: ModelFields( ModelFieldsValidator { fields: [ Field { name: "name", lookup_key: Simple { key: "name", py_key: Py( 0x00007ff1c40d6d70, ), path: LookupPath( [ S( "name", Py( 0x00007ff1c40d63b0, ), ), ], ), }, name_py: Py( 0x00007ff1df754af0, ), validator: WithDefault( WithDefaultValidator { default: Default( Py( 0x00007ff1dfb78940, ), ), on_error: Raise, validator: Nullable( NullableValidator { validator: Str( StrValidator { strict: false, coerce_numbers_to_str: false, }, ), name: "nullable[str]", }, ), validate_default: false, copy_default: false, name: "default[nullable[str]]", undefined: Py( 0x00007ff1dc854dc0, ), }, ), frozen: false, }, Field { name: "type", lookup_key: Simple { key: "type", py_key: Py( 0x00007ff1c40d6330, ), path: LookupPath( [ S( "type", Py( 0x00007ff1c40d5d30, ), ), ], ), }, name_py: Py( 0x00007ff1df754d70, ), validator: Union( UnionValidator { mode: Smart, choices: [ ( Str( StrValidator { strict: false, coerce_numbers_to_str: false, }, ), None, ), ( DefinitionRef( DefinitionRefValidator { definition: "ABIType", }, ), None, ), ], custom_error: None, strict: false, name: "union[str,ABIType]", }, ), frozen: false, }, Field { name: "components", lookup_key: Simple { key: "components", py_key: Py( 0x00007ff1c40d6e30, ), path: LookupPath( [ S( "components", Py( 0x00007ff1c40d5a70, ), ), ], ), }, name_py: Py( 0x00007ff1dedd95b0, ), validator: WithDefault( WithDefaultValidator { default: Default( Py( 0x00007ff1dfb78940, ), ), on_error: Raise, validator: Nullable( NullableValidator { validator: List( ListValidator { strict: false, item_validator: Some( DefinitionRef( DefinitionRefValidator { definition: "ABIType", }, ), ), min_length: None, max_length: None, name: OnceLock( "list[ABIType]", ), fail_fast: false, }, ), name: "nullable[list[ABIType]]", }, ), validate_default: false, copy_default: false, name: "default[nullable[list[ABIType]]]", undefined: Py( 0x00007ff1dc854dc0, ), }, ), frozen: false, }, Field { name: "internal_type", lookup_key: Simple { key: "internalType", py_key: Py( 0x00007ff1dca0a670, ), path: LookupPath( [ S( "internalType", Py( 0x00007ff1dca0a670, ), ), ], ), }, name_py: Py( 0x00007ff1dca0ac70, ), validator: WithDefault( WithDefaultValidator { default: Default( Py( 0x00007ff1dfb78940, ), ), on_error: Raise, validator: Nullable( NullableValidator { validator: Str( StrValidator { strict: false, coerce_numbers_to_str: false, }, ), name: "nullable[str]", }, ), validate_default: false, copy_default: false, name: "default[nullable[str]]", undefined: Py( 0x00007ff1dc854dc0, ), }, ), frozen: false, }, Field { name: "indexed", lookup_key: Simple { key: "indexed", py_key: Py( 0x00007ff1c40d78f0, ), path: LookupPath( [ S( "indexed", Py( 0x00007ff1c3f0d6f0, ), ), ], ), }, name_py: Py( 0x00007ff1dca0b9f0, ), validator: WithDefault( WithDefaultValidator { default: Default( Py( 0x00007ff1dfb63c80, ), ), on_error: Raise, validator: Bool( BoolValidator { strict: false, }, ), validate_default: false, copy_default: false, name: "default[bool]", undefined: Py( 0x00007ff1dc854dc0, ), }, ), frozen: false, }, ], model_name: "EventABIType", extra_behavior: Allow, extras_validator: None, strict: false, from_attributes: false, loc_by_alias: true, }, ), class: Py( 0x0000562fc25956c0, ), post_init: None, frozen: false, custom_init: false, root_model: false, undefined: Py( 0x00007ff1dc854dc0, ), name: "EventABIType", }, ), ), min_length: None, max_length: None, name: OnceLock( "list[EventABIType]", ), fail_fast: false, }, ), validate_default: false, copy_default: true, name: "default[list[EventABIType]]", undefined: Py( 0x00007ff1dc854dc0, ), }, ), frozen: false, }, Field { name: "anonymous", lookup_key: Simple { key: "anonymous", py_key: Py( 0x00007ff1c3f0cfb0, ), path: LookupPath( [ S( "anonymous", Py( 0x00007ff1c3f0d1b0, ), ), ], ), }, name_py: Py( 0x00007ff1de9cd230, ), validator: WithDefault( WithDefaultValidator { default: Default( Py( 0x00007ff1dfb63c80, ), ), on_error: Raise, validator: Bool( BoolValidator { strict: false, }, ), validate_default: false, copy_default: false, name: "default[bool]", undefined: Py( 0x00007ff1dc854dc0, ), }, ), frozen: false, }, ], model_name: "EventABI", extra_behavior: Ignore, extras_validator: None, strict: false, from_attributes: false, loc_by_alias: true, }, ), class: Py( 0x0000562fc25aad10, ), post_init: None, frozen: false, custom_init: false, root_model: false, undefined: Py( 0x00007ff1dc854dc0, ), name: "EventABI", }, ), frozen: false, }, ], model_name: "ContractEvent", extra_behavior: Ignore, extras_validator: None, strict: false, from_attributes: false, loc_by_alias: true, }, ), class: Py( 0x0000562fc45ee510, ), post_init: Some( Py( 0x00007ff1dce1d170, ), ), frozen: false, custom_init: true, root_model: false, undefined: Py( 0x00007ff1dc854dc0, ), name: "ContractEvent", }, ), definitions=[Model(ModelValidator { revalidate: Never, validator: ModelFields(ModelFieldsValidator { fields: [Field { name: "name", lookup_key: Simple { key: "name", py_key: Py(0x7ff1c40d5ff0), path: LookupPath([S("name", Py(0x7ff1c40d5630))]) }, name_py: Py(0x7ff1df754af0), validator: WithDefault(WithDefaultValidator { default: Default(Py(0x7ff1dfb78940)), on_error: Raise, validator: Nullable(NullableValidator { validator: Str(StrValidator { strict: false, coerce_numbers_to_str: false }), name: "nullable[str]" }), validate_default: false, copy_default: false, name: "default[nullable[str]]", undefined: Py(0x7ff1dc854dc0) }), frozen: false }, Field { name: "type", lookup_key: Simple { key: "type", py_key: Py(0x7ff1c40d5670), path: LookupPath([S("type", Py(0x7ff1c40d75b0))]) }, name_py: Py(0x7ff1df754d70), validator: Union(UnionValidator { mode: Smart, choices: [(Str(StrValidator { strict: false, coerce_numbers_to_str: false }), None), (DefinitionRef(DefinitionRefValidator { definition: "ABIType" }), None)], custom_error: None, strict: false, name: "union[str,...]" }), frozen: false }, Field { name: "components", lookup_key: Simple { key: "components", py_key: Py(0x7ff1c40d5570), path: LookupPath([S("components", Py(0x7ff1c40d55b0))]) }, name_py: Py(0x7ff1dedd95b0), validator: WithDefault(WithDefaultValidator { default: Default(Py(0x7ff1dfb78940)), on_error: Raise, validator: Nullable(NullableValidator { validator: List(ListValidator { strict: false, item_validator: Some(DefinitionRef(DefinitionRefValidator { definition: "ABIType" })), min_length: None, max_length: None, name: OnceLock(<uninit>), fail_fast: false }), name: "nullable[list[...]]" }), validate_default: false, copy_default: false, name: "default[nullable[list[...]]]", undefined: Py(0x7ff1dc854dc0) }), frozen: false }, Field { name: "internal_type", lookup_key: Simple { key: "internalType", py_key: Py(0x7ff1dca0a670), path: LookupPath([S("internalType", Py(0x7ff1dca0a670))]) }, name_py: Py(0x7ff1dca0ac70), validator: WithDefault(WithDefaultValidator { default: Default(Py(0x7ff1dfb78940)), on_error: Raise, validator: Nullable(NullableValidator { validator: Str(StrValidator { strict: false, coerce_numbers_to_str: false }), name: "nullable[str]" }), validate_default: false, copy_default: false, name: "default[nullable[str]]", undefined: Py(0x7ff1dc854dc0) }), frozen: false }], model_name: "ABIType", extra_behavior: Allow, extras_validator: None, strict: false, from_attributes: false, loc_by_alias: true }), class: Py(0x562fc27945d0), post_init: None, frozen: false, custom_init: false, root_model: false, undefined: Py(0x7ff1dc854dc0), name: "ABIType" })], cache_strings=True)
The pydantic-core SchemaValidator used to validate instances of the model.
- __repr__() str
Return repr(self).
- __signature__: ClassVar[Signature] = <Signature (*args, contract: ape.contracts.base.ContractTypeWrapper, abi: ethpm_types.abi.EventABI) -> None>
The synthesized __init__ [Signature][inspect.Signature] of the model.
- from_receipt(receipt: ReceiptAPI) list[ContractLog]
Get all the events from the given receipt.
- Parameters:
receipt (
ReceiptAPI
) – The receipt containing the logs.- Returns:
list[
ContractLog
]
- property info: str
NatSpec info derived from the contract-type developer-documentation.
- property name: str
The name of the contract event, as defined in the contract.
- poll_logs(start_block: int | None = None, stop_block: int | None = None, required_confirmations: int | None = None, new_block_timeout: int | None = None) Iterator[ContractLog]
Poll new blocks. Optionally set a start block to include historical blocks.
NOTE: This is a daemon method; it does not terminate unless an exception occurs.
Usage example:
for new_log in contract.MyEvent.poll_logs(): print(f"New event log found: block_number={new_log.block_number}")
- Parameters:
start_block (Optional[int]) – The block number to start with. Defaults to the pending block number.
stop_block (Optional[int]) – Optionally set a future block number to stop at. Defaults to never-ending.
required_confirmations (Optional[int]) – The amount of confirmations to wait before yielding the block. The more confirmations, the less likely a reorg will occur. Defaults to the network’s configured required confirmations.
new_block_timeout (Optional[int]) – The amount of time to wait for a new block before quitting. Defaults to 10 seconds for local networks or
50 * block_time
for live networks.
- Returns:
Iterator[
ContractLog
]
- query(*columns: str, start_block: int = 0, stop_block: int | None = None, step: int = 1, engine_to_use: str | None = None) DataFrame
Iterate through blocks for log events
- Parameters:
*columns (str) –
*
-based argument for columns in the DataFrame to return.start_block (int) – The first block, by number, to include in the query. Defaults to
0
.stop_block (Optional[int]) – The last block, by number, to include in the query. Defaults to the latest block.
step (int) – The number of blocks to iterate between block numbers. Defaults to
1
.engine_to_use (Optional[str]) – query engine to use, bypasses query engine selection algorithm.
- Returns:
pd.DataFrame
- range(start_or_stop: int, stop: int | None = None, search_topics: dict[str, Any] | None = None, extra_addresses: list | None = None) Iterator[ContractLog]
Search through the logs for this event using the given filter parameters.
- Parameters:
start_or_stop (int) – When also given
stop
, this is the earliest block number in the desired log set. Otherwise, it is the total amount of blocks to get starting from0
.stop (Optional[int]) – The latest block number in the desired log set. Defaults to delegating to provider.
search_topics (Optional[dict]) – Search topics, such as indexed event inputs, to query by. Defaults to getting all events.
extra_addresses (Optional[list[
AddressType
]]) – Additional contract addresses containing the same event type. Defaults to only looking at the contract instance where this event is defined.
- Returns:
Iterator[
ContractLog
]