se3000 / ruby-eth

Gem for creating and signing Ethereum transactions.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Transaction "from" is always nil for signed transaction

DSalko opened this issue · comments

Unable to recover sender's address from a signed transaction.
How to reproduce:

tx=Eth::Tx.decode("0xf8a90285012a05f2008292da94809826cceab68c387726af962713b64cb5cb3cca80b844a9059cbb0000000000000000000000001111db021688b8bb7923caca9e941df7ade5059900000000000000000000000000000000000000000000000ad78ebc5ac620000026a02f28bcd3eb0c98e488df30fdad478d222a9936ad6e04bc6b88bc97febbcfc02ea059cd01219feb6d777c86757c1d893bcc9fc90607d6e86e95fb886fd231558a35")

2.4.2 :002 > tx.from
 => nil

tx.signature is present

In example I used this transaction: https://etherscan.io/tx/0x18d2b9638253b6ab4627d9d9203dbec07a9233dae97c0cb2aaf01e7c62bd285e

Any suggestions?

Same behaviour here.

This could have something to do with my own report #22

You need to set the chain ID(aka network ID):

Eth.configure {|config| config.chain_id = 1}
hex = "0xf8a90285012a05f2008292da94809826cceab68c387726af962713b64cb5cb3cca80b844a9059cbb0000000000000000000000001111db021688b8bb7923caca9e941df7ade5059900000000000000000000000000000000000000000000000ad78ebc5ac620000026a02f28bcd3eb0c98e488df30fdad478d222a9936ad6e04bc6b88bc97febbcfc02ea059cd01219feb6d777c86757c1d893bcc9fc90607d6e86e95fb886fd231558a35"
tx = Eth::Tx.decode hex
tx.hash #=> "0x18d2b9638253b6ab4627d9d9203dbec07a9233dae97c0cb2aaf01e7c62bd285e"
tx.from #=> "0x37020b9384692BE78a4f180992d4f3F3Bd85f478"

By default the gem is configured to 0, which means it will work for writing to any chain, but it means that to parse a sender you may need to check ID 0 and the ID of the chain you're on. We could probably make that automatic, but you'd still need to configure your chain ID.

You can find more chain ID details and list of networks here.