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::Client#transact_and_wait expects gas_limit *kwargs method param and does not respect :gas_limit attr_accessor #221

Closed zackisaacs closed 1 year ago

zackisaacs commented 1 year ago

I'm using this gem in my project to create tokens, sign transactions, etc. It's been super helpful -- thank you!

I was struggling to understand why the :gas_limit attr_accessor I set after creating a new Eth::Client wasn't being respected, i.e.

      infura = Eth::Client.create('https://polygon-mainnet.infura.io/v3/xxx')
      infura.max_priority_fee_per_gas = 50 * Eth::Unit::GWEI
      infura.max_fee_per_gas = 150 * Eth::Unit::GWEI
      infura.gas_limit = 70000

I would submit transactions, they'd fail, I'd view them on polygonscan, and then see that the gas limit used for the transaction was 51000, which was much lower than the gas_limit attr_accessor I'd just set. I realize now this is because transact_and_wait and the underlying transact methods look for a gas_limit kwarg and fall back to Tx.estimate_intrinsic_gas(contract.bin) + Tx::CREATE_GAS instead of using the gas_limit attr_accessor.

Assuming this is the interface you want to keep, as opposed to making transactions respect the attr_accessor, I might suggest noting this behavior in the method docs and wiki. If you agree this would be useful, I'd be happy to submit a PR to this end.

q9f commented 1 year ago

Thanks for reporting, this is a bit unclean. There is really no point in setting the gas limit per client because each transaction will be different. I'll take a look at the code/documentation.

Meanwhile, just use the gas_limit argument for each transact call.