100% Accurate Gas Estimates With New Node RPC Methods

Apr 29, 2024 • 3 months ago

100% Accurate Gas Estimates With New Node RPC Methods

Two new custom RPC methods have been released on the Tenderly Node, providing 100% accurate gas estimates for single and bundled transactions. These methods, available on all supported networks on the Tenderly Node, are part of the custom tenderly_ namespace:

  • tenderly_estimateGas
  • tenderly_estimateGasBundle

These new methods are a major improvement to the default eth_estimateGas method. They rely on our "Smart Estimates,” which ensure no internal revert happens due to “out of gas.” The response is packed into the “Smart Estimates” object, which has the following fields (for now):

  • gas: Offers a 100% accurate estimate of the gas required to complete the transaction successfully without an "out of gas" error while taking into account handled reverts.
  • gasUsed: Displays the actual amount of gas used in the transaction, including refunds.

For bundled transactions, the tenderly_estimateGasBundle method returns a list of objects for each transaction, providing the same detailed gas estimation and usage information as the single transaction method.

Example request

curl https://mainnet.gateway.tenderly.co/$GATEWAY_KEY -d '{
   "id":0,
   "jsonrpc":"2.0",
   "method":"tenderly_estimateGasBundle",
   "params":[
      [
         {
            "from":"0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0",
            "to":"0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84",
            "data":"0x095ea7b30000000000000000000000009008d19f58aabd9ed0d60971565aa8510560ab410000000000000000000000000000000000000000000000000c1291a92f17a100"
         },
         {
            "from":"0x9008D19f58AAbD9eD0D60971565AA8510560ab41",
            "to":"0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84",
            "data":"0x23b872dd0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca00000000000000000000000009008d19f58aabd9ed0d60971565aa8510560ab410000000000000000000000000000000000000000000000000c1291a92f17a100"
         },
         {
            "from":"0x9008D19f58AAbD9eD0D60971565AA8510560ab41",
            "to":"0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84",
            "data":"0x095ea7b30000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca00000000000000000000000000000000000000000000000000c1291a92f17a100"
         },
         {
            "from":"0x9008D19f58AAbD9eD0D60971565AA8510560ab41",
            "to":"0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0",
            "data":"0xea598cb00000000000000000000000000000000000000000000000000c1291a92f17a100"
         }
      ],
      "19561494"
   ]
}'

Example response

{
  "id": 0,
  "jsonrpc": "2.0",
  "result": [
    {
      "gas": "0x12579"
    },
    {
      "gas": "0x108a4"
    },
    {
      "gas": "0xa621"
    },
    {
      "gas": "0x10560"
    }
  ]
}

Both methods consume 40 Tenderly Units (TU) per run and expect the same parameters as tenderly_simulateTransaction and tenderly_simulateBundle. Check the RPC Reference.

💡
Log into Tenderly Node to get the RPC link and access token.