Closed brent-ridian closed 1 month ago
Thanks @brent-ridian. Growing pains. This is due to an update in the hexbytes
library. We can have a patch for this out very soon. Until then here's a pretty quick yet ugly fix, just to get you unstuck:
class RawTx0xPrefixMiddleware(Web3Middleware):
def request_processor(self, method: "RPCEndpoint", params: Any) -> Any:
if method == "eth_sendRawTransaction":
raw_tx = params[0]
if not raw_tx.startswith("0x"):
params = [f"0x{raw_tx}"]
return method, params
# create and configure web3 resources:
w3: Web3 = Web3( Web3.HTTPProvider(POLYGON_INFURA_URL) )
w3.middleware_onion.inject(RawTx0xPrefixMiddleware, layer=0)
w3.middleware_onion.inject(ExtraDataToPOAMiddleware, layer = 0)
w3.middleware_onion.add(PythonicMiddleware)
Apologies for the bit of friction but thanks for testing out the new major version 👌🏼
We were actually able to sneak this into a newer minor that was just released @brent-ridian. web3.py v7.2.0
should have this fix.
Many thanks, fselmo!
I can confirm that web3 version 7.2.0 fixes this issue for me.
What happened?
In the code section below is a very stripped down version of code that we use to do a transfer of USDC on Polygon. Infura is our node service provider.
This code used to work with the previous version of web3, version 6.20.2.
But now it fails with the stack trace in the error section below
I am fairly certain that some code change in the latest web3 is what caused the above.
Less clear is whether this is a bug in web3, or if it is just web3 now being more strict. Consider this note from the v6 to v7 Migration Guide:
Any advice or recommendation for working around this would be appreciated.
Code that produced the error
Full error output
Fill this section in if you know how this could or should be fixed
No response
web3 Version
7.1.0
Python Version
3.12.4
Operating System
win
Output from
pip freeze