Skip to content

Commit fd62194

Browse files
authored
Add topic to ContractEvent docs. (#3586)
* Add topic to `ContractEvent` docs. * `myEvent` -> `MyEvent` * Newsfragment for #3586
1 parent b369340 commit fd62194

File tree

2 files changed

+25
-20
lines changed

2 files changed

+25
-20
lines changed

docs/web3.contract.rst

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,43 +1108,47 @@ For example:
11081108
myContract = web3.eth.contract(address=contract_address, abi=contract_abi)
11091109
tx_hash = myContract.functions.myFunction().transact()
11101110
receipt = web3.eth.get_transaction_receipt(tx_hash)
1111-
myContract.events.myEvent().process_receipt(receipt)
1111+
myContract.events.MyEvent().process_receipt(receipt)
11121112
11131113
.. py:class:: ContractEvent
11141114
11151115
Attributes
11161116
~~~~~~~~~~
11171117

1118-
The :py:class:`ContractEvent` class provides attributes for each event. Access the event attributes through `Contract.events.myEvent`.
1118+
The :py:class:`ContractEvent` class provides attributes for each event. Access the event attributes through `Contract.events.MyEvent`.
11191119

1120-
.. py:attribute:: ContractEvent.myEvent(*args, **kwargs).abi_element_identifier
1120+
.. py:attribute:: ContractEvent.MyEvent(*args, **kwargs).abi_element_identifier
11211121
11221122
The signature of the event assigned to the class ``__name__`` during initialization.
11231123

1124-
.. py:attribute:: ContractEvent.myEvent(*args, **kwargs).name
1124+
.. py:attribute:: ContractEvent.MyEvent(*args, **kwargs).name
11251125
11261126
A string representing the event, receive or fallback name.
11271127

1128-
Use :py:attr:`ContractEvent.myEvent(*args, **kwargs).signature` when the event arguments are needed.
1128+
Use :py:attr:`ContractEvent.MyEvent(*args, **kwargs).signature` when the event arguments are needed.
11291129

1130-
This is an alias of :py:attr:`ContractEvent.myEvent(*args, **kwargs).event_name`.
1130+
This is an alias of :py:attr:`ContractEvent.MyEvent(*args, **kwargs).event_name`.
11311131

1132-
.. py:attribute:: ContractEvent.myEvent(*args, **kwargs).signature
1132+
.. py:attribute:: ContractEvent.MyEvent(*args, **kwargs).signature
11331133
11341134
A string representing the event signature.
11351135

1136-
.. py:attribute:: ContractEvent.myEvent(*args, **kwargs).abi
1136+
.. py:attribute:: ContractEvent.MyEvent(*args, **kwargs).abi
11371137
11381138
The event ABI with the type, name, inputs.
11391139

1140-
.. py:attribute:: ContractEvent.myEvent(*args, **kwargs).argument_names
1140+
.. py:attribute:: ContractEvent.MyEvent(*args, **kwargs).argument_names
11411141
11421142
The event input names.
11431143

1144-
.. py:attribute:: ContractEvent.myEvent(*args, **kwargs).argument_types
1144+
.. py:attribute:: ContractEvent.MyEvent(*args, **kwargs).argument_types
11451145
11461146
The event input types.
11471147

1148+
.. py:attribute:: ContractEvent.MyEvent(*args, **kwargs).topic
1149+
1150+
The event topic represented by a hex encoded string from the keccak signature.
1151+
11481152
Methods
11491153
~~~~~~~
11501154

@@ -1172,9 +1176,9 @@ Methods
11721176
11731177
my_contract = web3.eth.contract(address=contract_address, abi=contract_abi)
11741178
1175-
# get ``myEvent`` logs from block 1337 to block 2337 where the value for the
1179+
# get ``MyEvent`` logs from block 1337 to block 2337 where the value for the
11761180
# event argument "eventArg1" is either 1, 2, or 3
1177-
my_contract.events.myEvent().get_logs(
1181+
my_contract.events.MyEvent().get_logs(
11781182
argument_filters={"eventArg1": [1, 2, 3]},
11791183
from_block=1337,
11801184
to_block=2337,
@@ -1187,14 +1191,14 @@ Methods
11871191

11881192
Extracts the pertinent logs from a transaction receipt.
11891193

1190-
If there are no errors, ``process_receipt`` returns a tuple of :ref:`Event Log Objects <event-log-object>`, emitted from the event (e.g. ``myEvent``),
1194+
If there are no errors, ``process_receipt`` returns a tuple of :ref:`Event Log Objects <event-log-object>`, emitted from the event (e.g. ``MyEvent``),
11911195
with decoded output.
11921196

11931197
.. code-block:: python
11941198
11951199
>>> tx_hash = contract.functions.myFunction(12345).transact({'to':contract_address})
11961200
>>> tx_receipt = w3.eth.get_transaction_receipt(tx_hash)
1197-
>>> rich_logs = contract.events.myEvent().process_receipt(tx_receipt)
1201+
>>> rich_logs = contract.events.MyEvent().process_receipt(tx_receipt)
11981202
>>> rich_logs[0]['args']
11991203
{'myArg': 12345}
12001204
@@ -1211,12 +1215,12 @@ Methods
12111215
12121216
>>> tx_hash = contract.functions.myFunction(12345).transact({'to':contract_address})
12131217
>>> tx_receipt = w3.eth.get_transaction_receipt(tx_hash)
1214-
>>> processed_logs = contract.events.myEvent().process_receipt(tx_receipt)
1218+
>>> processed_logs = contract.events.MyEvent().process_receipt(tx_receipt)
12151219
>>> processed_logs
12161220
(
12171221
AttributeDict({
12181222
'args': AttributeDict({}),
1219-
'event': 'myEvent',
1223+
'event': 'MyEvent',
12201224
'logIndex': 0,
12211225
'transactionIndex': 0,
12221226
'transactionHash': HexBytes('0xfb95ccb6ab39e19821fb339dee33e7afe2545527725b61c64490a5613f8d11fa'),
@@ -1229,7 +1233,7 @@ Methods
12291233
12301234
# Or, if there were errors encountered during processing:
12311235
>>> from web3.logs import STRICT, IGNORE, DISCARD, WARN
1232-
>>> processed_logs = contract.events.myEvent().process_receipt(tx_receipt, errors=IGNORE)
1236+
>>> processed_logs = contract.events.MyEvent().process_receipt(tx_receipt, errors=IGNORE)
12331237
>>> processed_logs
12341238
(
12351239
AttributeDict({
@@ -1247,7 +1251,7 @@ Methods
12471251
'errors': LogTopicError('Expected 1 log topics. Got 0')})
12481252
})
12491253
)
1250-
>>> processed_logs = contract.events.myEvent().process_receipt(tx_receipt, errors=DISCARD)
1254+
>>> processed_logs = contract.events.MyEvent().process_receipt(tx_receipt, errors=DISCARD)
12511255
>>> assert processed_logs == ()
12521256
True
12531257
@@ -1261,11 +1265,11 @@ Methods
12611265
>>> tx_hash = contract.functions.myFunction(12345).transact({'to':contract_address})
12621266
>>> tx_receipt = w3.eth.get_transaction_receipt(tx_hash)
12631267
>>> log_to_process = tx_receipt['logs'][0]
1264-
>>> processed_log = contract.events.myEvent().process_log(log_to_process)
1268+
>>> processed_log = contract.events.MyEvent().process_log(log_to_process)
12651269
>>> processed_log
12661270
AttributeDict({
12671271
'args': AttributeDict({}),
1268-
'event': 'myEvent',
1272+
'event': 'MyEvent',
12691273
'logIndex': 0,
12701274
'transactionIndex': 0,
12711275
'transactionHash': HexBytes('0xfb95ccb6ab39e19821fb339dee33e7afe2545527725b61c64490a5613f8d11fa'),

newsfragments/3586.docs.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Include ``topic`` attribute in ``ContractEvent`` docs.

0 commit comments

Comments
 (0)