Swap trade in Uniswap fails using uniswap-python standard functions

Question:

I am trying to do a simple trade using uniswap-python and it doesn’t work.

Sample code:

from uniswap import Uniswap
provider = "https://polygon-mainnet.infura.io/v3/"+INFURA_API_KEY
uniswap = Uniswap(address, private_key, version = 3, provider)
result = uniswap.make_trade(USDT, WMATIC, 10)

Result:

raise ExtraDataLengthError(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('0xd3...d0')

I’ve checked PoA docs and tested all options without success. I always get the same message.
There are enough funds in my wallet to do the trade.
Any clues?

Asked By: The Dare Guy

||

Answers:

This is a problem with the web3 provider used internally by the uniswap-python module. If you’re running on Polygon or another Proof of Authority chain (BNB for instance), you need to tell that to the web3 provider:

from web3.middleware import geth_poa_middleware
uniswap.w3.middleware_onion.inject(geth_poa_middleware, layer=0)
Answered By: kfx
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.