VeChain Docs
  • Welcome to VeChain
  • Blockchain Basics
    • Introduction to blockchain
    • Introduction to digital property
    • The evolution of the internet
  • Introduction to VeChain
    • About the VeChain blockchain
      • Consensus Deep Dive
      • Governance
    • Dual-Token Economic Model
      • VeChain (VET)
      • VeThor (VTHO)
    • Acquire VeChain Assets
    • Sustainability
  • Core Concepts
    • Networks
      • Thor Solo Node
      • Testnet
      • Mainnet
    • Nodes
      • Node Rewards Programme
    • Blocks
      • Block Model
    • Transactions
      • Transaction Model
      • Transaction Fees
      • Transaction Calculation
      • Meta Transaction Features
        • Transaction Uniqueness
        • Controllable Transaction Lifecycle
        • Clauses (Multi-Task Transaction)
        • Fee Delegation
          • Multi-Party Payment (MPP)
          • Designated Gas Payer (VIP-191)
        • Transaction Dependency
    • Block Explorers
    • Wallets
      • VeWorld
        • User Guide
          • Setup
          • Wallet
          • Signing
          • Activities
          • Settings
        • FAQ
      • Sync2
        • User Guide
          • Setup
          • Wallet
          • Signing
          • Activities
          • Settings
        • FAQ
      • Sync
        • User Guide
          • Wallet
          • Ledger Device
          • Browser dApps and web
          • Interact with dApps
          • Activities
          • Settings
          • Report an Issue
          • Contributing
        • FAQ
    • EVM Compatibility
      • VeChain Modifications
      • Methodology
      • Test Coverage
        • Gas model
        • Raw transaction
        • hardhat specific
          • Ganache failures
          • evm_increaseTime
        • Failures in constructor
        • eth_sign
        • Contract address prediction
        • BadBeacon proxy address at 0x1
      • How to Recreate
      • Additional Information
        • Using Governance Contracts
        • ERC1820/ERC777 Testnet
        • Delegate Options
    • Account Abstraction
      • UserOperation
      • Bundler
      • EntryPoint Contract
      • Account Factory Contract
      • Paymaster Contract
    • Token Bound Accounts
  • How to run a node
    • Nodes
    • How to run a Thor Solo Node
    • Custom Network
    • Connect Sync2 to a Thor Solo Node
  • Developer Resources
    • Getting Started
    • How to build on VeChain
      • Connect to the Network
      • Read Data
        • Read Blocks
        • Read Transactions
        • Read Accounts
        • States & Views
        • Events & Logs
        • VET Transfers
      • Write Data
        • Transactions
        • Fee Delegation
      • Listen to Changes
        • Events
        • VET Transfers
        • Transactions
        • Blocks
        • Beats
      • Build with Hardhat
      • Utilities
        • BigInt and Unit-Handling
        • Name Service Lookups
    • Example dApps
      • Buy me a Coffee
      • Token Bound Accounts
      • PWA with Privy and Account Abstraction
    • EVM Compatibility for Developers
      • Key Architectural Differences and Optimizations
      • Practical Implications for Developers: Key Considerations
      • RPC Methods (Detailed Breakdown)
      • Frequently Asked Questions (FAQs)
      • VeChain Blockchain Specifications
      • Key Differences Between VeChain and Ethereum (Summary)
      • Best Practices for Developing on VeChainThor
    • How to verify Address-Ownership
      • Next.js Session Verification
    • Debug Reverted Transactions
    • Account Abstraction
    • VIP-191: Designated Gas Payer
      • How to Integrate VIP-191 (I)
      • How to Integrate VIP-191 (II)
      • How to Integrate VIP-191 (III)
    • Index with Graph Node
      • Setup with Docker
      • Index with OpenZeppelin
        • Create Subgraph Project
        • Configure Contracts
        • Deploy Subgraph and start Indexing
        • Track Subgraph Indexing
        • Access Subgraph
        • Update Subgraph
    • SDKs & Providers
      • SDK
        • Architecture
        • Accounts
        • Bloom Filter
        • Certificates
        • Contracts
        • Cryptography
        • Debug
        • Encoding
        • Polls
        • Subscriptions
        • Thor Client
        • Transactions
      • Thor DevKit
        • Installation
        • Usage
          • Cryptography
          • Accounts
          • Encoding
          • Transactions
          • Certificates
          • Bloom Filter
      • DApp Kit
        • v2
          • Installation
          • React
            • Installation
            • Usage
          • Vanilla JS
            • Installation
            • Usage
          • Core
            • Installation
            • Usage
          • Theme Variables
          • i18n
        • v1
          • Installation
          • React
            • Installation
            • Usage
          • Vanilla JS
            • Installation
            • Usage
          • Core
            • Installation
            • Usage
          • Theme Variables
          • i18n
          • Node Polyfills
          • V0 to V1
        • v0
          • Installation
          • Usage
          • React
            • Installation
            • Usage
          • Vanilla (UI)
            • Installation
            • Usage
          • Styles (UI)
          • i18n
      • DevPal
      • Web3-Providers-Connex
        • Installation
        • Usage
      • Connex
        • Installation
        • API Specification
    • Frameworks & IDEs
      • Hardhat
      • Remix
    • Built-in Contracts
    • VORJ
    • Useful Links
  • How to contribute
Powered by GitBook
On this page
  • What is gas?
  • Intrinsic Gas Calculation
  • Proof of Work
  • Total Gas Price

Was this helpful?

  1. Core Concepts
  2. Transactions

Transaction Calculation

The math behind gas fee calculation on the VeChainThor blockchain.

PreviousTransaction FeesNextMeta Transaction Features

Last updated 1 year ago

Was this helpful?

What is gas?

Blockchain networks often refer to transaction fees as gas. Gas refers to the unit that measures the amount of computation effort required to execute operations on the blockchain network. This is a fee that is paid by the transaction sender and received by the blockchain network validator.

Intrinsic Gas Calculation

The VeChainThor blockchain transaction model is capable of containing clauses which allows a single transaction to carry out multiple tasks. Therefore, the total gas cost of the transaction needs to include all the clauses gas costs in the transaction.

The total gas, gtotalg_{total}gtotal​, required for a transaction can be computed as:

gtotal=g0+∑i(gtypei+gdatai+gvmi)g_{total} = g0 + \sum_i(g_{type}^i+g_{data}^i+g_{vm}^i)gtotal​=g0+∑i​(gtypei​+gdatai​+gvmi​)

  • where g0=5,000g_0 = 5,000g0​=5,000

  • There are two types of gtypeg_{type}gtype​

    • Regular transaction : 16,000

    • Contract creation : 48,000

  • gdatai=4⋅nzi+68⋅nnzig_{data}^i = 4 \cdot n_z^i + 68 \cdot n_{nz}^igdatai​=4⋅nzi​+68⋅nnzi​

    • nzin_z^inzi​ is the number of bytes equal to zero within the data in the ithi^{th}ith clause and nnzin_{nz}^innzi​ the number of bytes not equal to zero

  • gvmig_{vm}^igvmi​ is the gas cost returned by the virtual machine for executing the ithi^{th}ith clause.

Proof of Work

The VeChainThor blockchain allows for transaction-level proof of work (PoW) and converts the proved work into extra gas price that will be used by the system to generate more reward to the block generator, the Authority Masternode, that validates the transaction. In other words, users can utilize their local computational power to make their transactions more likely to be included in a new block.

with the following constraint

The VTHO reward for packing the transaction into a new block is computed as:

From the above equations, we know that

Total Gas Price

The total gas price for the transaction sender is computed as:

and the total price for block generators as

It can be seen that the gas price used to calculate the transaction cost depends solely on the input gas-price coefficient while the reward for packing the transaction into a block varies due to the transaction-level proof-of-work mechanism.

In particular, the computational work can be proved through fields Nonce and BlockRef in the transaction model. Let nnn and ggg represent the values of the transaction fields Nonce and Gas, respectively. We use bbb to denote the number of the block indexed by transaction field BlockRef and hhh the number of the block that includes the transaction. Let Ω\OmegaΩ denote the transaction without fields Nonce and Signature, SSS the transaction sender's account address, PPP the base gas price, HHH the hash function and EEE the recursive length prefix (RLP) encoding function.

The PoW, www, is defined as:

w=min(264−1,2256−1H(H(E(Ω∥S))∥n))w = min(2^{64}-1, \frac {{2^{256}-1}}{H(H(E(\Omega \parallel S))\parallel n)})w=min(264−1,H(H(E(Ω∥S))∥n)2256−1​)

The extra gas price, Δ\DeltaΔ, is computed as:

ΔP=P0(1gmin[g,w103(11.04)h−13600⋅24⋅3])\Delta P = P_0(\frac1{g}min[g,\frac w{10^3}(\frac 1{1.04})^\frac {h-1}{3600\cdot24\cdot3}])ΔP=P0​(g1​min[g,103w​(1.041​)3600⋅24⋅3h−1​])

∣h−h0∣≤30\mid h - h_0 \mid \leq 30∣h−h0​∣≤30

r=310g∗(P0(1+ϕ)+ΔP)r = \frac3{10}g^*(P_0(1+\phi) + \Delta P)r=103​g∗(P0​(1+ϕ)+ΔP)

where ϕ∈[0,1]\phi \in [0,1]ϕ∈[0,1] is the gas price coefficient and g∗g^*g∗ the actual amount of gas used for executing the transaction.

Since h0h_0h0​ is a valid block number, BlockRef must refer to an existing block, that is, it's value must equal the first four bytes of an existing block ID;

The transaction must be packed into a block within the period of 30 blocks after block bbb, or otherwise, the PoW would not be recognized by the system;

The extra gas price ΔP\Delta PΔP can not be greater than base gas price P.

gtotal=gbase+gbaseϕ255g^{total} = g^{base} + g^{base} \frac\phi{255}gtotal=gbase+gbase255ϕ​

gtotal=gbase+gbaseϕ255+ΔPg^{total} = g^{base} + g^{base} \frac\phi{255} + \Delta Pgtotal=gbase+gbase255ϕ​+ΔP

Where gbaseg^{base}gbase is the gas used by the transaction and ϕ\phiϕ is the value of field GasPriceCoef(a value between 0-255) and ΔP\Delta PΔP the extra gas price converted from the proven local computational work.