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

# Gas Heuristics

These gas estimates apply to native exchange transactions on Injective Core v1.21.0 when the exchange parameter `fixed_gas_enabled` is `true`. Check the parameter on the network where you submit the transaction. On Mainnet:

```bash theme={null}
curl -fsS https://sentry.lcd.injective.network/injective/exchange/v2/exchangeParams \
  | jq '.params.fixed_gas_enabled'
```

The suggested transaction gas limit (`gasWanted`) adds an estimated 120,000 gas for transaction checks to the exchange message gas. For multiple messages, budget for the sum of their message costs and the checks for the whole transaction. Simulate the exact transaction and leave headroom when setting the limit.

Binary options markets were removed in v1.21.0. Leave binary options fields empty when submitting `MsgBatchUpdateOrders`.

## Single messages

| Native exchange message | Fixed message gas | Suggested gas limit |
| - | -: | -: |
| `MsgCreateSpotLimitOrder` | 432,000 | 552,000 |
| `MsgCreateSpotLimitOrder` (post only) | 482,000 | 602,000 |
| `MsgCreateSpotMarketOrder` | 432,000 | 552,000 |
| `MsgCreateSpotMarketOrder` (immediate atomic) | 420,000 | 540,000 |
| `MsgCancelSpotOrder` | 242,000 | 362,000 |
| `MsgCreateDerivativeLimitOrder` | 452,000 | 572,000 |
| `MsgCreateDerivativeLimitOrder` (post only) | 512,000 | 632,000 |
| `MsgCreateDerivativeMarketOrder` | 442,000 | 562,000 |
| `MsgCreateDerivativeMarketOrder` (immediate atomic) | 430,000 | 550,000 |
| `MsgCancelDerivativeOrder` | 252,000 | 372,000 |
| `MsgDeposit` | 210,000 | 330,000 |
| `MsgWithdraw` | 200,000 | 320,000 |
| `MsgSubaccountTransfer` | 100,000 | 220,000 |
| `MsgExternalTransfer` | 180,000 | 300,000 |
| `MsgIncreasePositionMargin` | 230,000 | 350,000 |
| `MsgDecreasePositionMargin` | 240,000 | 360,000 |

Order creation values include the 12,000 gas charge for address order admission where applicable. Immediate atomic market orders use the base charge.

For a Good Till Block (GTB) limit order, apply the `1.1` multiplier to the base creation charge before adding the 12,000 admission charge. Use the post only base if applicable. For example, a regular spot GTB order uses `420,000 × 1.1 + 12,000 = 474,000` message gas. With the ante allowance, the suggested gas limit is `594,000`.

## Batch messages

For these estimates, allow 120,000 gas for transaction checks plus about 3,000 gas per listed order. Add the fixed message charge for each order.

| Message | Estimated gas limit for N orders |
| - | -: |
| `MsgBatchCreateSpotLimitOrders` with regular orders | 120,000 + N × 435,000 |
| `MsgBatchCancelSpotOrders` | 120,000 + N × 245,000 |
| `MsgBatchCreateDerivativeLimitOrders` with regular orders | 120,000 + N × 455,000 |
| `MsgBatchCancelDerivativeOrders` | 120,000 + N × 255,000 |

### MsgBatchUpdateOrders

The v2 message has the following Go fields. Protobuf tags are omitted for readability.

```go theme={null}
type MsgBatchUpdateOrders struct {
    Sender                            string
    SubaccountId                      string
    SpotMarketIdsToCancelAll          []string
    DerivativeMarketIdsToCancelAll    []string
    SpotOrdersToCancel                []*OrderData
    DerivativeOrdersToCancel          []*OrderData
    SpotOrdersToCreate                []*SpotOrder
    DerivativeOrdersToCreate          []*DerivativeOrder
    BinaryOptionsOrdersToCancel       []*OrderData       // Leave empty on v1.21.
    BinaryOptionsMarketIdsToCancelAll []string           // Leave empty on v1.21.
    BinaryOptionsOrdersToCreate       []*DerivativeOrder // Leave empty on v1.21.
    SpotMarketOrdersToCreate          []*SpotOrder
    DerivativeMarketOrdersToCreate    []*DerivativeOrder
    BinaryOptionsMarketOrdersToCreate []*DerivativeOrder // Leave empty on v1.21.
}
```

Use the single message table to price each operation in the batch.

| Message fields | Gas calculation |
| - | - |
| `SpotOrdersToCreate`, `DerivativeOrdersToCreate` | Add the limit order charge for each order, including any post only or GTB pricing. |
| `SpotMarketOrdersToCreate`, `DerivativeMarketOrdersToCreate` | Add the market order charge for each order. Use the immediate atomic rate where applicable. |
| `SpotOrdersToCancel`, `DerivativeOrdersToCancel` | Add the corresponding cancellation charge per listed order. |
| `SpotMarketIdsToCancelAll`, `DerivativeMarketIdsToCancelAll` | Set `SubaccountId`. Count the orders in each targeted market for that subaccount and apply the corresponding cancellation charge to each order found. |

Budget about 3,000 gas for transaction checks per explicit order or cancel all market ID.

| Example operations in one batch | Estimated gas |
| - | -: |
| Base transaction checks | 120,000 |
| Cancel three spot orders | 735,000 |
| Create two regular derivative limit orders | 910,000 |
| Create one post only spot limit order | 485,000 |
| Cancel all four spot orders across two markets | 974,000 |
| **Suggested gas limit** | **3,224,000** |

## Additional gas

* A permissionless token's pre-send contract hook can charge additional gas to the transaction. Account for the hook separately because transaction simulation omits that charge in v1.21.0.
* Legacy `injective.exchange.v1beta1` order, batch, and margin messages can incur extra market reads during conversion to v2. The release estimates about 1,700 gas per spot market read and 2,300 gas per derivative market read.
* For calls from Solidity, estimate the full EVM transaction. The [Exchange precompile](https://docs.injective.network/developers-evm/exchange-precompile.md) uses exchange constants as part of its own gas accounting and can also charge for owner blacklist queries.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.