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

# Transaction Simulation

> Estimating gas consumption before broadcasting transactions

Simulation executes the transaction against the current chain state without
broadcasting it. The chain returns how much gas the transaction would consume.

## Using `simulate` Directly

```typescript theme={"system"}
const gasEstimate = await client.simulate(address, messages, "optional memo");
```

`simulate` returns the gas used as a `number`. You can then add a buffer and
compute the fee:

```typescript theme={"system"}
import { calculateFee, GasPrice } from "@cosmjs/stargate";

const gasEstimate = await client.simulate(address, messages, memo);
const gasLimit = Math.ceil(gasEstimate * 1.5);
const fee = calculateFee(gasLimit, GasPrice.fromString("0.025uatom"));

const result = await client.signAndBroadcast(address, messages, fee, memo);
```

## How `"auto"` Uses Simulation

When you pass `"auto"` or a number, the client calls `simulate` internally:

1. The transaction is built with an empty signature and sent to the chain's
   `Simulate` endpoint
2. The chain executes it in a read-only context and returns `gasUsed`
3. The client multiplies by the gas multiplier (default 1.4x, or the value you
   passed)
4. `calculateFee` converts the gas limit to a `StdFee` using the configured gas
   price

The 1.4x default was chosen because Cosmos SDK 0.47+ sometimes uses
significantly more gas than simulation predicts. Earlier versions used 1.3x.

## Caveats

* Simulation is an **estimate**. Actual gas can differ if chain state changes
  between simulation and execution.
* The multiplier buffer protects against this, but extremely volatile state
  (e.g. many concurrent transactions) may still cause out-of-gas errors.
* Simulation requires an RPC connection. Offline clients cannot simulate.
