Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The field extraData is 97 bytes, but should be 32. It is quite likely that you are connected to a POA chain

I deployed a private network via geth and posted a smart contract there. Accounts are set in the genesis block

enter image description here

I'm creating a python function in which I want to call a smart contract function

import web3
import json
class Estate():
    with open("abi.txt", 'r') as file:
        abi = json.load(file)
    contract_address = "0x4FD52ce1140d67b8c721AB7967eeca44FE56c883"
    contract_address = web3.Web3.toChecksumAddress(contract_address)
    w3 = web3.Web3(web3.HTTPProvider('http://127.0.0.1:8545'))
    con = w3.eth.contract(address=contract_address, abi=abi)

    def create_estate(self, address, info, square):
        address = web3.Web3.toChecksumAddress(address)
        print(self.con.functions.create_estate(address, info, square).transact())
        #self.w3.eth.waitForTransactionReceipt(tx)

c = Estate()
c.create_estate("0xE64021f5387Dc5FA859e0641437a45542D511e7E","street", 200)

I am getting the following error:

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#geth-style-proof-of-authority for more details. The full extraData is: HexBytes('0xda83010a0d846765746888676f312e31372e328777696e646f7773000000000053ea481c4aca3824d51d3c8103abe60179d3f1c4ec68a0c87d5533e8e0580e14433b6cf8a285b519add550d59e70e60619721861b2d855cb7a175978610bb65500')

like image 316
Ilya Avatar asked Jan 23 '26 00:01

Ilya


1 Answers

The error comes from a discrepancy in the block format between your private geth network (or a public test network like Rinkeby) and the main network.

You can work around this by adding a middleware to your Web3 object:

from web3.middleware import geth_poa_middleware

Then inject the middleware:

w3 = web3.Web3(web3.HTTPProvider('http://127.0.0.1:8545'))
w3.middleware_onion.inject(geth_poa_middleware, layer=0)

I had the same error as you and fixed it based on the solution here:

https://github.com/blockchain-etl/ethereum-etl/issues/178

The web3 documentation also mentions this:

https://web3py.readthedocs.io/en/stable/middleware.html#why-is-geth-poa-middleware-necessary

like image 111
Samuel Dion-Girardeau Avatar answered Jan 25 '26 22:01

Samuel Dion-Girardeau



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!