> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tenderly.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Gas Estimation

> Estimate gas with the Simulation API using estimate_gas, or get 100% accurate limits via the tenderly_estimateGas RPC methods before sending.

The Simulation API allows you to simulate transactions and obtain the estimated gas usage needed to successfully execute the transactions.

Set `estimate_gas: true` in the request to get gas estimates.

<Note>
  Note: you can get 100% accurate gas estimates using the [**`tenderly_estimateGas`**](/node-rpc/rpc-reference?network=ethereum-mainnet\&method=tenderly_estimateGas) and [**`tenderly_estimateGasBundle`**](/node-rpc/rpc-reference?network=ethereum-mainnet\&method=tenderly_estimateGasBundle) RPC methods.
</Note>

**Example**

Make sure to store the access key securely in a `.env` file.

```ts title="example.ts" showLineNumbers theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}

dotenv.config();

const { TENDERLY_ACCOUNT_SLUG, TENDERLY_PROJECT_SLUG, TENDERLY_ACCESS_KEY } = process.env;

const simulateTransaction = async () => {
  const { data } = await axios.post(
    `https://api.tenderly.co/api/v1/account/${TENDERLY_ACCOUNT_SLUG}/project/${TENDERLY_PROJECT_SLUG}/simulate`,
    {
      // Simulation Configuration
      save: true,
      save_if_fails: false,
      estimate_gas: true,
      simulation_type: 'quick',
      network_id: '1',
      // Standard EVM Transaction object (sample values)
      from: '0xdc6bdc37b2714ee601734cf55a05625c9e512461',
      to: '0x6b175474e89094c44da98b954eedeac495271d0f',
      input: '0x095ea7b3000000000000000000000000f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1000000000000000000000000000000000000000000000000000000000000012b',
      gas: 8000000,
      gas_price: 0,
      value: 0,
    },
    {
      headers: {
        'X-Access-Key': TENDERLY_ACCESS_KEY as string,
      },
    },
  );

  console.log({ data });
};

simulateTransaction();
```

This calculates the maximum gas needed for the transaction. After a successful simulation, check the `gas_used` field in the `transaction` structure.

**Result**

```json title="example.json" showLineNumbers theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
"transaction": {
    ...
    "gas": 8000000,
    "gas_price": 0,
    "gas_fee_cap": 0,
    "gas_tip_cap": 0,
    "cumulative_gas_used": 0,
    "gas_used": 51534, // Gas estimates
    "effective_gas_price": 0,
    ...
 }
```
