ethjsonrpc icon indicating copy to clipboard operation
ethjsonrpc copied to clipboard

Missing 0x prefix for hex data

Open danielksan81 opened this issue 8 years ago • 7 comments

Hi @ all, Since release 1.5.6 of geth (https://github.com/ethereum/go-ethereum/releases/tag/v1.5.6), the RPC implementation only accepts hex data with prefix '0x', which is missing in the current implementation. As a sample, the client is handling it incorrect at line https://github.com/ConsenSys/ethjsonrpc/blob/master/ethjsonrpc/client.py#L150.

Regards Daniel

danielksan81 avatar Feb 03 '17 08:02 danielksan81

The following lines are also affected as far as I can see: https://github.com/ConsenSys/ethjsonrpc/blob/master/ethjsonrpc/client.py#L116 https://github.com/ConsenSys/ethjsonrpc/blob/master/ethjsonrpc/client.py#L128

danielksan81 avatar Feb 03 '17 13:02 danielksan81

@danielksan81 thats correct, also for parity the 0x prefix is requiered most of the times. As a workaround, i'm doing this

from eth_utils import add_0x_prefix

And adding it when requiered contract_tx = c.create_contract(c.eth_coinbase(), add_0x_prefix(compiled), gas=300000) for example

UPDATE: ok i found it hard to implement in the call and call_with_transaction functions so i guess it will be needed to update the lib

reiven avatar Jun 06 '17 17:06 reiven

Hi, we used monkey patching to patch these methods in a first step. For further development we switched now to web3 python.

danielksan81 avatar Aug 18 '17 10:08 danielksan81

I can say this is a blocker. The module doesn't work at all for calling smart contract function calls. I haven't tried it, but it seems that @reiven's PR would fix these issues.

tudorconstantin avatar Oct 05 '17 15:10 tudorconstantin

Unfortunately there seems to be even more work beyond @reiven 's work to be done on almost every method e.g. eth_newFilter:

Traceback (most recent call last):
  File "tick.py", line 83, in <module>
    cl.monitor_contract(contract_addr)
  File "tick.py", line 75, in monitor_contract
    self.install_filter(contract_address)
  File "tick.py", line 23, in install_filter
    installed_filter_id = self.client.eth_newFilter(from_block=0, address=contract_address)
  File "/Users/lookfwd/Desktop/foobar/.env/lib/python2.7/site-packages/ethjsonrpc/client.py", line
...
    raise BadResponseError(response)
ethjsonrpc.exceptions.BadResponseError: {u'jsonrpc': u'2.0', u'id': 1, u'error': {u'message': u'invalid argument 0: hex string without 0x prefix', u'code': -32602}}

Fix: At line 507.

        _filter = {
            'fromBlock': "0x{}".format(from_block),  # <-- Add the 0x/format
            'toBlock':   to_block,
            'address':   address,
            'topics':    topics,
        }

(or one of the suggested @reiven 's methods.)

lookfwd avatar Nov 06 '17 09:11 lookfwd

I will take a look at that method and fix it, thanks @lookfwd

reiven avatar Nov 06 '17 12:11 reiven

Same issue here.

bl4ck5un avatar Apr 16 '18 20:04 bl4ck5un