How Tenderly Enables 100% Accurate Eth Gas Estimations in Transaction Simulations
Learn how Tenderly enables 100% accurate gas estimations in a single run and prevents internal transactions from failing with out-of-gas errors. Start getting the most precise gas estimates with Tenderly Node or Simulation API.
In this post
eth_estimateGas endpoint is a crucial component in Web3 because it enables the estimation of the amount of gas required for executing a transaction. Gas represents the computational and storage resources required to execute smart contracts and perform operations on the Ethereum network.
However, obtaining accurate gas estimates is essential for ensuring that transactions have enough gas to complete successfully without running out of computational resources. Without sufficient gas, both Web3 developers and end users can experience transaction failures and waste their resources on reverted transactions. On the other hand, providing more gas than necessary can result in unnecessary fees and inefficiencies.
So, evaluating gas usage precisely is essential for warning your users that their transactions may spend more money than actually needed. However, the current algorithm leaves room for improvement, so we decided to explore an alternative solution. And we’ve found a way to achieve 100% gas estimation accuracy and bring it to Web3 developers.
How are gas estimates currently calculated on Ethereum?
The standard implementation of gas estimation on the Ethereum network typically utilizes a binary search algorithm. The goal of this algorithm is to find the optimal amount of gas required for a transaction to be executed successfully.
The binary search nature of this algorithm allows it to quickly converge on the optimal gas limit. By successively narrowing down the range of possible gas limits, the algorithm reduces the number of computations required to find the correct gas estimation from O(N) to O(logN), N being the maximum amount of gas a transaction can have in a block.
However, the nature of the current algorithm has certain downsides:
- The process is complex and resource-consuming, requiring around 25 transaction executions to estimate the optimal gas limit.
- Computing gas accurately is also challenging in cases where smart contracts encounter unsuccessful internal transactions in their logic. This means that you still exhaust your resources, yet your transactions get reverted.
- Gas estimation inaccuracy has a negative effect on end users who may often underpay or overpay for gas, leaving them with unnecessary expenses and unsuccessful transactions.
- Finally, the network itself doesn’t benefit from a great number of reverted transactions since it still needs to execute them.
Calculating precise Ethereum gas estimates in a single run
At Tenderly, we’ve always wanted to support the growth and adoption of blockchain technology by supporting innovative teams building Web3 solutions. So, we’re always looking for ways to drive the space forward and provide solutions to the obstacles standing in the way of smart contract engineers.
So, we’re excited to have found a solution capable of finding gas estimates in a single run, eliminating the need for a binary search algorithm. Our solution significantly reduces the computational complexity from O(logN) to O(1), providing a significant advancement in gas estimation efficiency.
By leveraging this new approach, we can estimate the optimal gas limit required for transaction execution without the iterative process of raising or lowering it. This not only saves computational resources but also streamlines the gas estimation process, allowing for faster and more accurate transaction execution on the Ethereum network.
Preventing internal transactions from failing with “out of gas” errors
To further enhance gas estimations on Ethereum, we implemented a system that also tracks internal transaction failures caused by “out of gas” errors. Additionally, we revised the condition for lowering the gas amount. Rather than increasing the gas limit only when a simulation fails due to an out-of-gas error, we also bump it if any internal transaction fails because of the same issue.
How to get the most accurate gas estimates
In Tenderly, there are two ways to obtain 100% gas estimates for your or your users’ transactions:
1. Run eth_estimateGas in Tenderly Node: You can use our node as a service to get comprehensive and accurate gas estimates.
Just head over to the Tenderly Dashboard, open the Node page, and configure the RPC Request Builder to send your
2. Simulate transactions using Transaction Simulator: Whether you’re running simulations from the Tenderly Dashboard or you’ve integrated Simulation API, you can get 100% precise gas estimates prior to sending transactions on-chain. Plus, with Simulation API, you can expose this information to your dapp or wallet users, providing them with exact gas estimates and helping them save funds.
When running simulations, just make sure to specify
estimate_gas and set it to true. Then, you can check the gas field in the API response for the precise gas estimate.
Get 100% accurate gas estimates in Web3
With our new method of calculating the most accurate gas estimates, you can improve the user experience in your dapps. Just run
eth_estimateGas via Web3 Gateway and eliminate the risk of getting an incorrect response and, ultimately, failed transactions.
You can even offer the same information to your users by integrating Tenderly Simulation API. Your dapp or wallet users can always know the exact gas cost of their transactions even if they don’t come from technical backgrounds. In return, this will also help build confidence in the industry.
So, head over to the Tenderly Dashboard and start getting the most accurate gas estimation in Web3.
Subscribe to our newsletter