Skip to content

Commit 4833e25

Browse files
committed
Update docs to clarify when using sign-and-send with POA middleware
1 parent 3c3bdb1 commit 4833e25

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

docs/middleware.rst

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,13 @@ Proof of Authority
319319

320320
.. py:class:: web3.middleware.ExtraDataToPOAMiddleware
321321
322-
.. note::
323-
It's important to inject the middleware at the 0th layer of the middleware onion:
324-
``w3.middleware_onion.inject(ExtraDataToPOAMiddleware, layer=0)``
322+
.. important::
323+
It is **crucial** that this middleware is injected at the 0th layer of the
324+
middleware onion, using
325+
``w3.middleware_onion.inject(ExtraDataToPOAMiddleware, layer=0)``, to guarantee
326+
it is the *first* middleware to process the response and modify the ``extraData``
327+
field. This ensures it processes the field before any other middleware attempts
328+
to validate it.
325329

326330
``ExtraDataToPOAMiddleware`` is required to connect to ``geth --dev`` and may
327331
also be needed for other EVM compatible blockchains like Polygon or BNB Chain
@@ -423,10 +427,20 @@ The ``build`` method for this middleware builder takes a single argument:
423427
* An ``eth_keys.PrivateKey`` object
424428
* A raw private key as a hex string or byte string
425429

430+
.. important::
431+
Since this middleware signs transactions, it must always run after any middleware
432+
that modifies the transaction. Therefore, it is recommended to inject the signing
433+
middleware at the 0th layer of the middleware onion using
434+
``w3.middleware_onion.inject(SignAndSendRawMiddlewareBuilder.build(...), layer=0)``.
435+
Ensure that any transaction-modifying middleware exists in a higher layer within the
436+
onion so that it runs before the signing middleware.
437+
426438
.. note::
427-
Since this middleware signs the transaction, any middleware that modifies the
428-
transaction should run before this middleware. Therefore, it is recommended to
429-
inject the signing middleware at the 0th layer of the middleware onion.
439+
If used with ``ExtraDataToPOAMiddleware``, the injection order doesn't matter, as
440+
the ``extraData`` field isn't involved in transaction signing. The key is ensuring
441+
``SignAndSendRawMiddlewareBuilder`` runs after any middleware that modifies the
442+
transaction.
443+
430444

431445
.. code-block:: python
432446

0 commit comments

Comments
 (0)