Swisstronik Docs
  • 🇨🇭About Swisstronik
    • What is Swisstronik?
    • Swisstronik vs Ethereum
    • Useful links
  • 🌐General
    • Intel SGX
    • Governance
      • On-Chain Proposal
      • Formatting a Proposal
      • Submitting a Proposal
      • Governable Parameters
    • Community Pool
    • Accounts
    • Transactions
    • Gas and Fees
    • Coin & Tokens
  • ⚒️Development
    • Endpoints
    • Connect wallets
      • MetaMask (EVM) - Manual
      • Keplr (Cosmos)
      • Testnet Metamask (EVM) - Chainlist
      • Testnet MetaMask (EVM) - Manual
      • Testnet Keplr (Cosmos)
    • Get test coins
    • SwisstronikJS SDK
      • SwisstronikJS Functions
      • Swisstronik & Ethereum transactions
      • Transaction - code sample
      • Swisstronik & Ethereum calls
      • Call - code sample
    • Swisstronik CLI
      • Installation
      • Configuration
      • Key management
      • Queries
      • Sending SWTR
      • For SDI Issuers
    • Guides
      • Contract deployment - Hardhat
        • 1. Setting up the Hardhat environment
        • 2. Configure hardhat.config.js
        • 3. Write and compile the smart contract
        • 4. Deploy the smart contract
        • 5. Interact with the contract - Transaction
        • 6. Interact with the contract - Call
      • Contract deployment - Remix IDE
      • Deployment & Interaction PERC-20
        • ERC-20 & PERC-20
        • Sample PERC20 contract
        • Deployment & Interaction with contract
        • How to use encryption
      • Contract verification
      • SDI for dapp developers
    • Local testnet
    • Web3JS, Ethers, Viem and other third-party libraries
  • 🖥️Node setup
    • Setup SGX
      • Supported Hardware
      • Setup Intel SGX
    • Setup node
      • Mainnet
        • v1.0.1 Upgrade
      • Testnet
        • Install from .deb package
        • Configure node
        • Upgrade your testnet node
          • Swisstronik v3 Testnet
          • Swisstronik v4 Testnet
          • Swisstronik v5 Testnet
          • Swisstronik v5.1 Testnet
          • Swisstronik v6 Testnet
          • Swisstronik v7 Testnet
          • Swisstronik v8 Testnet
        • Seed Node
        • Live Peers
        • Genesis Mirror Download
    • CLI Cheatsheet
  • 🤝Delegators
    • What is a delegator?
    • Delegator Guide (CLI)
    • Delegators Security
Powered by GitBook
On this page
  • Gas and Fees
  • Prerequisite Readings​
  • Basics​
  • Implementation​
  1. General

Gas and Fees

PreviousTransactionsNextCoin & Tokens

Last updated 1 year ago

Gas and Fees

Users need to pay a fee to submit transactions on the Swisstronik network. As fees are handled differently on Ethereum and Cosmos, it is important to understand how the Swisstronik blockchain implements an Ethereum-type fee calculation, that is compatible with the Cosmos SDK.

Therefore this overview explains the basics of gas calculation, how to provide fees for transactions, and how the Ethereum-type fee calculation uses a fee market (EIP1559) for prioritizing transactions.

Prerequisite Readings

Basics

Why do Transactions Need Fees?

If anyone can submit transactions to a network at no cost, the network can be overrun by a handful of actors sending large numbers of fraudulent transactions to clog up the network and stop it from working.

The solution to this is a concept called “gas," which is a resource consumed throughout transaction execution. In practice, a small amount of gas is spent on each step of code execution, thus effectively charging for use of a validator’s resources and preventing malicious actors from halting a network at will.

What is Gas?

In general, gas is a unit that measures the computational intensity of a particular transaction — in other words, how much work would be required to evaluate and perform the job. Complex, multi-step transactions, such as a Cosmos transaction that delegates to a dozen validators, require more gas than simple, single-step transactions, such as a Cosmos transaction to send tokens to another address.

When referring to a transaction, “gas” refers to the total quantity of gas required for the transaction. For example, a transaction may require 300,000 units of gas to be executed.

Gas can be thought of as electricity (kWh) within a house or factory, or fuel for automobiles. The idea is that it costs something to get somewhere.

More on Gas:

More on Gas Calculations:

While gas refers to the computational work required for execution, fees refer to the amount of the tokens you actually spend to execute the transaction. They are derived using the following formula:

Total Fees = Gas * Gas Price (the price per unit of gas)

If “gas” was measured in kWh, the “gas price” would be the rate (in dollars per kWh) determined by your energy provider, and the “fees” would be your bill. Just as with electricity, gas price is liable to fluctuate over a given day, depending on network traffic.

More on Gas vs. Fees:

Gas fees on Cosmos are relatively straightforward. As a user, you specify two fields:

  1. A GasLimit corresponding to an upper bound on execution gas, defined as GasWanted

  2. One of Fees or GasPrice, which will be used to specify or calculate the transaction fees

The node will entirely consume the fees provided, then begin to execute the transaction. If the GasLimit is found to be insufficient during execution, the transaction will fail and roll back any changes made, without refunding the fees provided.

Validators for Cosmos SDK-based chains can specify their min-gas-prices that they will enforce when selecting transactions to include in blocks. Thus, transactions with insufficient fees will encounter delays or fail outright.

Fees on Ethereum include multiple implementations that were introduced over time.

Originally, a user would specify a GasPrice and GasLimit within a transaction—much like a Cosmos SDK transaction. A block proposer would receive the entire gas fee from each transaction in the block, and they would select transactions to include accordingly.

With proposal EIP-1559 and the London Hard fork, gas calculation changed. The GasPrice from above has now been split into two separate components: a BaseFee and PriorityFee. The BaseFee is calculated automatically based on the block size and is burned once the block is mined. The PriorityFee goes to the proposer and represents a tip, or an incentive for a proposer to include the transaction in a block.

Gas Price = Base Fee + Priority Fee

Within a transaction, users can specify a max_fee_per_gas corresponding to the total GasPrice and a max_priority_fee_per_gas corresponding to a maximum PriorityFee, in addition to specifying the gas_limit as before. All surplus gas that was not required for execution is refunded to the user.

More on Ethereum Fees:

Fundamentally, Swisstronik is a Cosmos SDK chain that enables EVM compatibility as part of a Cosmos SDK module. As a result of this architecture, all EVM transactions are ultimately encoded as Cosmos SDK transactions and update a Cosmos SDK-managed state.

Since all transactions are represented as Cosmos SDK transactions, transaction fees can be treated identically across execution layers. In practice, dealing with fees includes standard Cosmos SDK logic, some Ethereum logic, and custom Swisstronik logic. For the most part, fees are collected by the fee_collector module, then paid out to validators and delegators. A few key distinctions are as follows:

  1. Fee Market Module

    In order to support EIP-1559 gas and fee calculation on Swisstronik EVM layer, Swisstronik tracks the gas supplied for each block and uses that to calculate a base fee for future EVM transactions, thus enabling EVM dynamic fees and transaction prioritization as specified by EIP-1559.

    For EVM transactions, each node bypasses their local min-gas-prices configuration, and instead applies EIP-1559 fee logic—the gas price simply must be greater than both the global min-gas-price and the block's BaseFee, and the surplus is considered a priority tip. This allows validators to compute Ethereum fees without applying Cosmos SDK fee logic.

    Unlike on Ethereum, the BaseFee on Swisstronik is not burned, and instead is distributed to validators and delegators. Furthermore, the BaseFee is lower-bounded by the global min-gas-price (currently, the global min-gas-price parameter is set to zero, although it can be updated via Governance).

  2. EVM Gas Refunds

    Swisstronik refunds a fraction (at least 50% by default) of the unused gas for EVM transactions to approximate the current behavior on Ethereum.

How is Gas Calculated?

In general, there’s no way to know exactly how much gas a transaction will cost without simply running it. Using the Cosmos SDK, this can be done by . Otherwise, there are ways to estimate the amount of gas a transaction will require, based on the details of the transaction fields, and data. In the case of the EVM, for example, each bytecode operation has a .

How does Gas Relate to Fees?

How are Fees Handled on Cosmos?

At the beginning of each block, fees from the previous block are , after which they can be withdrawn and spent.

How are Fees Handled on Ethereum?

Implementation

How are Gas and Fees Handled on Swisstronik?

🌐
​
Cosmos SDK Gas
Ethereum Gas
​
​
​
Cosmos Gas Fees
Cosmos Tx Lifecycle
Ethereum Gas
​
simulating the Tx
corresponding amount of gas
Estimate Gas
Executing EVM Bytecode
Simulate a Cosmos SDK Tx
​
Cosmos Gas and Fees
Ethereum Gas and Fees
​
allocated to validators and delegators
​
Gas Calculation Docs
Proposal EIP-1559
​
​