Skip to main content
Standard EVM gas costs as bigint constants.
import {
  GAS_TRANSACTION,    // 21000n - Base tx
  GAS_TXDATAZERO,     // 4n - Zero byte
  GAS_TXDATANONZERO,  // 16n - Non-zero byte
  GAS_CREATE,         // 32000n - CREATE
  GAS_SSET,           // 20000n - SSTORE set
  GAS_SRESET,         // 5000n - SSTORE reset
  GAS_KECCAK256,      // 30n - Keccak base
  GAS_LOG,            // 375n - LOG base
  GAS_LOGTOPIC,       // 375n - Per topic
  GAS_LOGDATA,        // 8n - Per byte
} from 'voltaire-effect/primitives/GasConstants'

Calculation Functions

import {
  calculateTxIntrinsicGas,
  calculateMemoryExpansionCost,
  calculateSstoreCost,
  calculateKeccak256Cost,
  calculateLogCost,
  calculateCallCost,
  calculateMaxRefund,
} from 'voltaire-effect/primitives/GasConstants'

const intrinsic = calculateTxIntrinsicGas(calldata, isCreate, accessList)
const memCost = calculateMemoryExpansionCost(currentSize, newSize)
const logCost = calculateLogCost(topicCount, dataLength)

Example

const estimateGas = (data: Uint8Array): bigint => {
  let gas = GAS_TRANSACTION
  for (const byte of data) {
    gas += byte === 0 ? GAS_TXDATAZERO : GAS_TXDATANONZERO
  }
  return gas
}