> ## Documentation Index
> Fetch the complete documentation index at: https://seilabs-docs-skills-registry-and-templates.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 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 help developers and users estimate fees on Sei, please reference
[Sei Gas](https://seigas.com) and the associated
[APIs](https://docs.blocknative.com/gas-prediction/gas-platform) provided by
Blocknative. Their estimates are based on real-time SEI data and advanced ML
modeling to accurately and consistently estimate SEI transaction fees.

### 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.

## Using Blocknative's Gas API

To leverage Blocknative's Gas API, you will need an [API Key](https://docs.blocknative.com/gas-prediction/gas-platform#authentication). This API is free, but heavily rate limited, so it is recommended you get an API key. Once you have your key, you can request fee estimation for SEI:

```
curl -H "Authorization: your-apikey-here" https://api.blocknative.com/gasprices/blockprices?chainid=1329
```
