Gas

Gas

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

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 (opens in a new tab).

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 (opens in a new tab).

Current values

  • Mainnet (pacific-1): 0.02usei
  • Testnet (atlantic-2): 0.08usei
  • Devnet (arctic-1): 0.02usei

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.

seid tx bank send <from_address> <to_address> <amount> --gas <gas_limit> --gas-prices <gas_price> --fees <fee>

Using CosmJS

Gas fees must be sent in any CosmJS transaction using the StdFee object.

const fee = {
  amount: [{ denom: "usei", amount: "5000" }],
  gas: "200000",
};
const result = await client.signAndBroadcast(address, [msg], fee, memo);

Using EVM (wagmi)

import { sendTransaction } from 'wagmi/actions'
 
sendTransaction({
  request: {
    to: '0xRecipientAddress',
    value: '1000000000000000000', // 1 ETH
    gasPrice: '20000000000', // 20 Gwei
    gasLimit: '21000',
  },
})

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.
  • Use an optimizer (opens in a new tab) to reduce the size and efficiency of your smart contract.

Fee Grants

Sei allows users to pay for gas fees on behalf of other users. This feature is useful for dApps that want to cover the gas fees for their users. Learn more about Fee Grants in the Advanced Concepts section.