Does anyone have a detailed understanding of how eth_estimateGas works with regards to gasPrice and the current mempool state?

I have historically seen some really odd behavior when using eth_estimateGas on mainnet. I've seen both false positives and false negatives. In other words, I've seen an eth_estimateGas that tells me a tx would fail only to watch the tx succeed. And I've also seen an eth_estimateGas that tells me a tx would succeed only to watch it fail. And from these experiences, I take the result of eth_estimateGas with a huge grain of salt. I always assumed the reason was based on the state of the mempool at that moment when the node received my request. And since mempool is always changing and you don't know the actual mempool of the miners, you get inconsistency.

M question is: Is there any 100% reliable way to verify that a transaction will actually succeed or fail (and at what gas cost) totally unrelated to mempool, gas auctions, etc? I want a reliable way to say "yes my tx will succeed" and I don't want other transactions to be factored in. I want to assume the state of the blockchain is the recent block, or better yet, a specified block. One thought is, I could call eth_estimateGas with a gasPrice of like 9999999999999999999 or something really massive so that the node that receives my request would assume it always gets the first spot in the block (even though that's not the actual gas price I'll be using.

I've tried calling eth_estimateGas when setting the gasPrice, but I ran into some odd errors. I also noticed that calling eth_estimateGas using Infura is more likely to work than just using my geth node. I'm wondering if Infura is routing the call to Parity as well and maybe Parity handles the call differently than Geth.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.