@@ -319,9 +319,13 @@ Proof of Authority
319
319
320
320
.. py :class :: web3.middleware.ExtraDataToPOAMiddleware
321
321
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.
325
329
326
330
``ExtraDataToPOAMiddleware `` is required to connect to ``geth --dev `` and may
327
331
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:
423
427
* An ``eth_keys.PrivateKey `` object
424
428
* A raw private key as a hex string or byte string
425
429
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
+
426
438
.. 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
+
430
444
431
445
.. code-block :: python
432
446
0 commit comments