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

Smart Contract cli.transact_and_wait returning nil, instead for error message #223

Closed kyleboureston closed 2 months ago

kyleboureston commented 1 year ago

Hello,

When submitting transact_and_wait to a remote connect, I get nil instead of an error message. Would love a message so I can debug properly!

PS: to add, even when I get a Success transaction, I am still getting nil

Thank you

q9f commented 1 year ago

Yes, this means that your transaction didn't succeed. I just reviewed the logic and we throw an error, if something goes wrong and return a hash if it succeeds. However, currently, there is no logic to inform you if something happens to the transaction execution in the virtual machine.

I'll think about a better handling here.

zackisaacs commented 1 year ago

I've noticed the problem (transact_and_wait returns nil) when connecting to infura, even when the transaction succeeds. I believe the problem is not wait_for_tx(transact(contract, function, *args, **kwargs)) fails here:

https://github.com/q9f/eth.rb/blob/041aa92e50d59663b410698601dc9c92a6ccb23f/lib/eth/client.rb#L318

but that tx_succeeded? hash returns false shortly thereafter here:

https://github.com/q9f/eth.rb/blob/041aa92e50d59663b410698601dc9c92a6ccb23f/lib/eth/client.rb#L319

My guess is that the transaction receipt doesn't propagate to the network readers used by infura quickly enough when calling eth_get_transaction_receipt(hash) here:

https://github.com/q9f/eth.rb/blob/041aa92e50d59663b410698601dc9c92a6ccb23f/lib/eth/client.rb#L366

Writing and then not being able to read right after is a pretty common race condition. Could solve by updating tx_succeeded?(hash) to retry if tx_receipt["result"].nil? == true here:

https://github.com/q9f/eth.rb/blob/041aa92e50d59663b410698601dc9c92a6ccb23f/lib/eth/client.rb#L367

If this is something you'd like to see, I'd be happy to submit a PR.

q9f commented 1 year ago

I'll gladly review such a PR, thanks!