q9f / eth.rb

a straightforward library to build, sign, and broadcast ethereum transactions anywhere you can run ruby.
https://q9f.github.io/eth.rb
Apache License 2.0
200 stars 86 forks source link

eth/contract: "invalid argument 0: hex string has length 40, want 64 for common.Hash" #121

Closed unixneo closed 2 years ago

unixneo commented 2 years ago

Working with engineers from Chainstack and Infura, was able to get gas to work finally. Now, this is the error when deploying contracts:

{"jsonrpc":"2.0","id":25,"error":{"code":-32602,"message":"invalid argument 0: hex string has length 40, want 64 for common.Hash"}}

I traced this to client.rb in the params in the payload in send_command. Printing each time this method is called, the params change from 64 (0x + 64) chars to 40 (0x + 40) chars before the failure.

...........end debug...........
ARGS...........
["0xBA8Ca77d45161FCbfb591F77cc1303d7151f2C4E"]
END ARGS...........
def marshal(params) ["0xBA8Ca77d45161FCbfb591F77cc1303d7151f2C4E"]
ARRAY
def marshal(params) 0xBA8Ca77d45161FCbfb591F77cc1303d7151f2C4E
Hex
......payload................
{:jsonrpc=>"2.0",
 :method=>"eth_getTransactionByHash",
 :params=>["0xBA8Ca77d45161FCbfb591F77cc1303d7151f2C4E"],
 :id=>25}
......output................
parse source {"jsonrpc":"2.0","id":25,"error":{"code":-32602,"message":"invalid argument 0: hex string has length 40, want 64 for common.Hash"}}
{"jsonrpc"=>"2.0",
 "id"=>25,
 "error"=>
  {"code"=>-32602,
   "message"=>
    "invalid argument 0: hex string has length 40, want 64 for common.Hash"}}
...........end debug...........

This param is causing the error:

 :params=>["0xBA8Ca77d45161FCbfb591F77cc1303d7151f2C4E"],

The length is wrong; but I am not sure why.

Normally, it is like this:

ARGS...........
["0x8d2103f1592b6e978230c51341e45c6c0e65f8460d65397793cbf963add0e33f"]
END ARGS...........
def marshal(params) ["0x8d2103f1592b6e978230c51341e45c6c0e65f8460d65397793cbf963add0e33f"]
ARRAY
def marshal(params) 0x8d2103f1592b6e978230c51341e45c6c0e65f8460d65397793cbf963add0e33f
Hex
unixneo commented 2 years ago

This is not a bug in eth but a bug in my test code; fixed by Chris @Infura. Thanks Chris for your review.

https://infura.io/