DEV Community

ilija
ilija

Posted on • Updated on

web3.py and Polygon testnet Mumabi: ExtraDataLengthError

If you ever find yourself with ExatrDataLenghtError when you try to write something from your Python script (via web3.py) into smart contract deployed on Mumbai, you should consider injecting geth_poa_middleware into instance of web3Provider

from web3.middleware import geth_poa_middleware
self.w3Provider = Web3(Web3.HTTPProvider(provider))
self.w3Provider.middleware_onion.inject(geth_poa_middleware, layer=0)
Enter fullscreen mode Exit fullscreen mode

And this should solve situation.

Reason for this error is fact that some Proof-of-Authority implementation like go-ethereum (geth) doesn't implement yellow paper fully. It has some difference that need to be adjusted with middleware that web3.py provide us. Naimlly extraData field in each block shoould be maximum of 32-bytes and Geth’s PoA is 97 bytes. So this middleware modifies the block data before returning it.

Here us full error message:

web3.exceptions.ExtraDataLengthError: The field extraData is 97 bytes, but should be 32. It is quite likely that you are connected to a POA chain. Refer to http://web3py.readthedocs.io/en/stable/middleware.html#proof-of-authority for more details. The full extraData is: HexBytes('0xd78301000483626f7288676f312e32302e38856c696e75780000000000000000761548136a5f1862a71b2101f065486f94dd9914103df62281b714ce1d57c23d615abbff096f646f1e8428ebfd13fb59ca6d8a82e26735873e603739cf7d8a7d00')

More on this error you can find in web3.py official documentationweb3py
Section Why is geth_poa_middleware necessary?

Top comments (0)