-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sign_and_send_raw_middleware stopped working in 6.0: Object of type HexBytes is not JSON serializable #2936
Comments
You cannot pass Python objects to JSON-RPC. Make sure params are a hex string before calling `make_request`.
There is a test that specifically checks for |
@miohtama do you have a minimum reproducible example we can test against? I just ran using a local >>> from web3 import Web3, IPCProvider
>>> from web3.middleware import geth_poa_middleware, construct_sign_and_send_raw_middleware
>>> w3 = Web3(IPCProvider('...'))
>>> w3.middleware_onion.inject(geth_poa_middleware, layer=0)
>>> acct1 = w3.eth.coinbase
>>> w3.eth.account.enable_unaudited_hdwallet_features()
>>> seed = "SEED"
>>> acct2 = w3.eth.account.from_mnemonic(seed)
>>> w3.middleware_onion.add(construct_sign_and_send_raw_middleware(acct2))
>>> tx2 = {
... 'from': acct2.address,
... 'to': acct1,
... 'value': 1000,
... 'gas': 210000,
... 'gasPrice': 2,
... 'nonce': w3.eth.get_transaction_count(acct1)
... }
>>> w3.eth.send_transaction(tx2)
HexBytes('0x5dec76c3e7baa3b36f31ed945355465e0e44993b6c4e5b426d4559eb4c8a1df9') |
Thank you. Let me do a reprod! |
I'm having the same issue @miohtama how do you address it? |
- Don't assume some conversion is going to happen later down the line. The JSON-RPC asks for hexstr value, give it the hexstr value if we can guarantee that it is a hexstr. We already have the type as HexBytes so call ``.hex()`` on the value and send that as the param. - closes ethereum#2936
- Don't assume some conversion is going to happen later down the line. The JSON-RPC asks for hexstr value, give it the hexstr value if we can guarantee that it is a hexstr. We already have the type as HexBytes so call ``.hex()`` on the value and send that as the param. - closes ethereum#2936
- Don't assume some conversion is going to happen later down the line. The JSON-RPC asks for hexstr value, give it the hexstr value if we can guarantee that it is a hexstr. We already have the type as HexBytes so call ``.hex()`` on the value and send that as the param. - closes ethereum#2936
- Don't assume some conversion is going to happen later down the line. The JSON-RPC asks for hexstr value, give it the hexstr value if we can guarantee that it is a hexstr. We already have the type as HexBytes so call ``.hex()`` on the value and send that as the param. - closes #2936
What was wrong?
sign_and_send_raw_middleware
is used withLocalAccount
to send transactions with the locally imported private key, as opposed to the test EVM accounts.However, it no longer seems to work with JSON-RPC endpoints (not sure if specifically some JSON-RPCs).
The error is in the eth_sendRawTransaction
params
argument that gets passedHexBytes
object and Web 6.0'smake_request
cannot serialise this. Maybe this is why test don't catch it as EthereumTester is special.The error:
Traceback:
How can it be fixed?
In
sign_and_send_raw_middleware
changereturn make_request(RPCEndpoint("eth_sendRawTransaction"), [raw_tx])
to
return make_request(RPCEndpoint("eth_sendRawTransaction"), [raw_tx.hex()])
The text was updated successfully, but these errors were encountered: