> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sei.io/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 is a measure of computational effort required to execute a transaction or
contract on the Sei network. Gas fees are paid in Sei and are used to
incentivize validators to process transactions and smart contracts.

## Key Terms and Concepts

### Gas

A unit of measurement representing the work done to execute a transaction, "gas"
varies based on the complexity of the transaction being executed.

### Gas Price

The amount of Sei paid per unit of gas used when executing a transaction. The
gas price is set by the user and is used to calculate the fee for the
transaction.

### Gas Limit

The maximum amount of gas the user wants the transaction to use. If the gas
limit is set too low, the node attempting to run the transaction will run out of
gas and fail to complete the transaction, using up the entire max gas without
completing the transaction.

### Fee

`Fee = Gas Price * Gas Used`.

The gas limit caps the maximum possible charge at `Gas Price * Gas Limit`. Note
that on Sei, excess gas (the gas limit beyond the actual gas used) may not be
refunded in full or in part, so avoid setting gas limits far above what a
transaction actually needs. See
[Sei EVM vs Ethereum](/evm/differences-with-ethereum) for details.

To estimate fees on Sei, query the network directly using the standard EVM
JSON-RPC methods `eth_gasPrice`, `eth_maxPriorityFeePerGas`, and
`eth_feeHistory`. These return real-time gas pricing straight from the chain
with no third-party service required. See
[Estimating gas prices](#estimating-gas-prices) below for examples.

### Maximum Gas

The maximum gas limit for a transaction ensures that complex transactions do not
consume 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)
or by querying the `/consensus_params` of the RPC node itself (ex.
[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 are detailed in the
[chain registry](https://github.com/sei-protocol/chain-registry/blob/main/gas.json).

### Max Bytes

Each transaction has a maximum size in bytes, which is set per chain. This limit
can be queried on the RPC node directly using the `/consensus_params` endpoint.

### Max Gas for Queries

Since queries also use gas, there is a maximum gas limit for queries. This limit
is RPC specific, so check with your RPC provider to determine the maximum gas
limit for queries.

## Sending Gas in Transactions

When submitting a TX to be broadcast, users specify the gas price and the gas
limit to create the fee.

### Using `seid`

When using `seid`, the fee is set using the `--fees` flag, gas limit and gas
price can be set with `--gas` and `--gas-prices` flags respectively.

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

### Using EVM (wagmi)

```ts theme={"dark"}
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

Optimizing gas prices involves efficient smart contract coding practices:

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

## Estimating Gas Prices

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

* `eth_gasPrice` — current recommended gas price for legacy transactions.
* `eth_maxPriorityFeePerGas` — suggested priority fee (tip) for EIP-1559 transactions.
* `eth_feeHistory` — recent base fees and priority-fee percentiles, useful for building custom fee strategies.

Query the current gas price on mainnet (`pacific-1`) directly:

```sh theme={"dark"}
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={"dark"}
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();
```
