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

# Gas

> Understand gas pricing, limits, and optimization strategies for Sei transactions, with guides for sending transactions using seid and EVM interfaces.

Gas measures the computational effort required to execute a transaction or
contract on the Sei network. Transaction fees are paid in SEI, and they
incentivize validators to process transactions and smart contracts.

## Key terms and concepts

### Gas

Gas is a unit of measurement for the work done to execute a transaction. The
amount of gas depends on the complexity of the transaction.

### Gas price

The gas price is the amount of SEI paid per unit of gas that a transaction
uses. You set the gas price, and it is used to calculate the transaction fee.

### Gas limit

The gas limit is the maximum amount of gas that you want the transaction to
use. If the gas limit is too low, the node that executes the transaction runs
out of gas. The transaction then fails, and it uses up the entire gas limit.

### Fee

`Fee = Gas Price * Gas Used`.

The gas limit caps the maximum possible charge at `Gas Price * Gas Limit`. On
Sei, excess gas (the gas limit beyond the actual gas used) may not be refunded
in full or in part. Because of this, avoid gas limits far above what a
transaction needs. For details, see
[Sei EVM vs Ethereum](/evm/differences-with-ethereum).

To estimate fees on Sei, query the network directly with the standard EVM
JSON-RPC methods `eth_gasPrice`, `eth_maxPriorityFeePerGas`, and
`eth_feeHistory`. These methods return real-time gas pricing from the chain, so
you do not need a third-party service. For examples, see
[Estimating gas prices](#estimating-gas-prices) below.

### Maximum gas

The maximum gas limit for a transaction prevents complex transactions from
using excessive resources. You can find the maximum gas limits for each chain in
the
[Sei chain registry](https://github.com/sei-protocol/chain-registry/blob/main/gas.json).
You can also query the `/consensus_params` endpoint of the RPC node (for example,
[https://rpc.sei-apis.com/consensus\_params](https://rpc.sei-apis.com/consensus_params)).

### Minimum gas price

Sei enforces minimum gas prices to prevent spam transactions. These prices are
set per chain, and the
[chain registry](https://github.com/sei-protocol/chain-registry/blob/main/gas.json)
lists them.

### Max bytes

Each transaction has a maximum size in bytes, which is set per chain. You can
query this limit directly on the RPC node with the `/consensus_params` endpoint.

### Max gas for queries

Because queries also use gas, there is a maximum gas limit for queries. This
limit is specific to each RPC. To find it, check with your RPC provider.

## Sending gas in transactions

When you submit a transaction for broadcast, you specify the gas price and the
gas limit to create the fee.

### Using `seid`

With `seid`, the `--fees` flag sets the fee. You can set the gas limit with the
`--gas` flag and the gas price with the `--gas-prices` flag.

```sh theme={null}
seid tx bank send <from_address> <to_address> <amount> --gas <gas_limit> --gas-prices <gas_price> --fees <fee>
```

### Using EVM (wagmi)

```ts theme={null}
import { parseEther, parseGwei } from 'viem';
import { sendTransaction } from '@wagmi/core';
import { config } from './config'; // your wagmi config

await sendTransaction(config, {
  to: '0xRecipientAddress',
  value: parseEther('1'), // 1 SEI
  gasPrice: parseGwei('100'), // 100 gwei (legacy tx; omit to use EIP-1559 maxFeePerGas/maxPriorityFeePerGas)
  gas: 21000n
});
```

## Optimizing gas prices for smart contracts

To optimize gas prices, follow efficient coding practices for smart contracts:

* Minimize storage operations.
* Use fixed-size data structures where possible.
* Avoid unnecessary computations.

## Estimating gas prices

You can read real-time gas pricing directly from the network, without a third-party service. Sei's EVM RPC exposes the standard Ethereum JSON-RPC methods for gas estimation:

* `eth_gasPrice`: Returns the current recommended gas price for legacy transactions.
* `eth_maxPriorityFeePerGas`: Returns the suggested priority fee (tip) for EIP-1559 transactions.
* `eth_feeHistory`: Returns recent base fees and priority-fee percentiles. It helps you build custom fee strategies.

Query the current gas price on Sei Mainnet directly:

```sh theme={null}
curl -sS https://evm-rpc.sei-apis.com \
  -H "Content-Type: application/json" \
  --data '{"jsonrpc":"2.0","method":"eth_gasPrice","params":[],"id":1}'
```

Most EVM libraries wrap these methods for you. For example, with viem:

```ts theme={null}
import { createPublicClient, http } from 'viem';
import { sei } from 'viem/chains';

const client = createPublicClient({
  chain: sei,
  transport: http('https://evm-rpc.sei-apis.com')
});

// Legacy gas price
const gasPrice = await client.getGasPrice();

// EIP-1559 fee suggestion
const { maxFeePerGas, maxPriorityFeePerGas } = await client.estimateFeesPerGas();
```


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