> For the complete documentation index, see [llms.txt](https://quantumwing.gitbook.io/quantumwing/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://quantumwing.gitbook.io/quantumwing/transactions/gas-fees.md).

# Gas & Fees

## Overview

This document explains **gas fee mechanisms** in QuantumWing with practical examples. The gas model is **EVM-compatible** but adapted for quantum-safe transactions with Dilithium signatures.

{% hint style="info" %}
**Note:** Final gas pricing is still being evaluated. Examples use 10 Gwei baseline for illustration.
{% endhint %}

{% hint style="success" %}
**EIP-1559 (April 2026)**: QuantumWing now ships an EIP-1559 fee market — base fee per block + Type-2 transactions + base fee burn. New wallets should use Type-2. Native token rebranded from `ETH` placeholder to **QWING**. See [EIP-1559 Fee Market](/quantumwing/transactions/eip1559.md).
{% endhint %}

***

## Gas Basics

### What is Gas?

**Gas** is a unit of computation that measures how much work a transaction requires:

```
Transaction Cost = (Gas Limit × Gas Price) + Value Transferred

Example:
- Send 1 QWING to Alice
- Gas Limit: 21,000 (standard transfer)
- Gas Price: 10 Gwei
- Total Cost: 1.00021 QWING
  └─ 1.00000 QWING to Alice
  └─ 0.00021 QWING as gas fee
```

***

## Gas Limits by Operation

### Standard Operations

| Operation                  | Gas Limit             | Example Cost (10 Gwei) |
| -------------------------- | --------------------- | ---------------------- |
| **Simple Transfer**        | 21,000                | 0.00021 QWING          |
| **Dilithium Verification** | 0 (FREE)              | 0 QWING                |
| **Smart Contract Call**    | \~50,000-200,000      | 0.0005-0.002 QWING     |
| **Contract Deployment**    | \~1,000,000-3,000,000 | 0.01-0.03 QWING        |
| **QWVM Storage Write**     | \~20,000 per word     | 0.0002 QWING           |

**Why Dilithium is FREE?**

* Quantum-safe signature verification is a **core feature**
* No additional gas charge for Dilithium Mode 3 signatures
* Encourages quantum-safe transaction adoption

***

## Gas Price Tiers

### Example Pricing Levels

```go
// Possible gas price tiers (not finalized)
const (
    MinGasPrice      = 1 Gwei      // Minimum accepted
    StandardGasPrice = 10 Gwei     // Normal transactions
    FastGasPrice     = 50 Gwei     // Priority transactions
)
```

**User Choice:**

```bash
# Send transaction with standard gas price
$ quantum-wing send --to 0xABC... --amount 1 --gas-price 10gwei

# Priority transaction (faster inclusion)
$ quantum-wing send --to 0xABC... --amount 1 --gas-price 50gwei
```

***

## Transaction Cost Examples

### Example 1: Simple Transfer

**Scenario:** Alice sends 1 QWING to Bob.

```json
{
  "from": "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
  "to": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
  "value": "1000000000000000000",  // 1 QWING in Wei
  "gas": 21000,
  "gasPrice": "10000000000",       // 10 Gwei in Wei
  "nonce": 42
}
```

**Cost Breakdown:**

```
Gas Fee = 21,000 × 10 Gwei = 210,000 Gwei = 0.00021 QWING

Total Deducted from Alice:
├─ Transfer amount:  1.00000 QWING
├─ Gas fee:          0.00021 QWING
└─ Total:            1.00021 QWING

Recipient (Bob) receives:
└─ 1.00000 QWING (gas fee NOT deducted from transfer)

Validator earns:
└─ 0.00021 QWING (gas fee)
```

***

### Example 2: Smart Contract Call

**Scenario:** Deploy QWVM counter contract.

```json
{
  "from": "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
  "to": null,  // Contract creation
  "data": "0x608060405234801561001057600080fd5b50...",  // WASM bytecode
  "gas": 1500000,
  "gasPrice": "10000000000",  // 10 Gwei
  "nonce": 43
}
```

**Cost Breakdown:**

```
Estimated Gas: 1,500,000 (contract deployment)
Gas Price: 10 Gwei
Gas Fee = 1,500,000 × 10 Gwei = 15,000,000 Gwei = 0.015 QWING

Actual Usage: 1,234,567 gas (may be less)
Refund = (1,500,000 - 1,234,567) × 10 Gwei = 0.00265433 QWING

Final Cost:
├─ Gas used:       0.01234567 QWING
├─ Refund:        -0.00265433 QWING
└─ Net cost:       0.00969134 QWING
```

***

### Example 3: High-Volume Batch

**Scenario:** Send 100 transactions in one block.

```bash
# Batch transfer script
for i in {1..100}; do
  quantum-wing send \
    --to 0xRECIPIENT_$i \
    --amount 0.1 \
    --gas-price 10gwei \
    --nonce $i
done
```

**Cost Analysis:**

```
Per Transaction:
├─ Transfer: 0.1 QWING
├─ Gas fee: 0.00021 QWING
└─ Total:   0.10021 QWING

100 Transactions:
├─ Transfer: 10 QWING
├─ Gas fees: 0.021 QWING
└─ Total:    10.021 QWING

Validator Earnings (this block):
└─ 0.021 QWING from 100 transactions
```

***

## Block Gas Limit

### Per-Block Capacity

```go
const MaxGasPerBlock = 30,000,000  // 30M gas per block
```

**Block Capacity Examples:**

| Transaction Type     | Gas per TX   | Max TX per Block |
| -------------------- | ------------ | ---------------- |
| Simple transfers     | 21,000       | **1,428 TX**     |
| Token transfers      | \~50,000     | 600 TX           |
| Smart contract calls | \~100,000    | 300 TX           |
| Contract deployments | \~1,000,000  | 30 TX            |
| Mixed workload       | \~50,000 avg | 600 TX           |

**Full Block Example:**

```
Block #12345:
├─ Gas limit:       30,000,000
├─ Gas used:        29,856,000 (99.5% full)
├─ Transactions:    1,422
├─ Average gas/TX:  21,000
├─ Gas price:       10 Gwei
└─ Validator earns: 0.2986 QWING
```

***

## Fee Distribution Models

### Model 1: 100% to Validators (Current Example)

```
Transaction Fee Flow:
┌──────────────┐
│    Sender    │ Pays: Value + Gas Fee
└──────┬───────┘
       │
       ├─> Recipient:  Value (100%)
       └─> Validator:  Gas Fee (100%)
```

**Example Block Earnings:**

```
Block with 1,000 transactions:
├─ Gas per TX:   21,000
├─ Gas price:    10 Gwei
├─ Fee per TX:   0.00021 QWING
└─ Validator:    0.21 QWING total
```

***

### Model 2: EIP-1559 Style (Shipped — Type-2 transactions)

EIP-1559 is live (B-4): Type-2 transactions carry a burned base fee plus a priority tip to the proposer, accepted alongside legacy transactions in the same block. See [EIP-1559 Fee Market](/quantumwing/transactions/eip1559.md) for the full settlement model.

```
Transaction Fee = Base Fee + Priority Fee

Base Fee:
├─ Dynamic (adjusts per block)
├─ Burned (deflationary)
└─ Target: 50% block fullness

Priority Fee:
├─ Goes to validator
└─ User sets (for faster inclusion)
```

**Example with EIP-1559:**

```json
{
  "maxFeePerGas": "20000000000",        // 20 Gwei max
  "maxPriorityFeePerGas": "2000000000", // 2 Gwei tip
  "gasLimit": 21000
}
```

**Calculation:**

```
Current Base Fee: 15 Gwei
Priority Fee: 2 Gwei
Effective Gas Price: min(20, 15 + 2) = 17 Gwei

Total Fee = 21,000 × 17 Gwei = 357,000 Gwei = 0.000357 QWING

Distribution:
├─ Base fee (15 Gwei × 21,000): 0.000315 QWING → BURNED 🔥
└─ Priority (2 Gwei × 21,000):  0.000042 QWING → Validator
```

**Base Fee Adjustment:**

```go
// Pseudo-code for dynamic base fee
func calculateBaseFee(parentBaseFee, gasUsed, gasTarget uint64) uint64 {
    if gasUsed == gasTarget {
        return parentBaseFee  // No change
    }
    
    delta := parentBaseFee / 8  // Max 12.5% change per block
    
    if gasUsed > gasTarget {
        // Block >50% full → increase fee
        increase := delta * (gasUsed - gasTarget) / gasTarget
        return parentBaseFee + increase
    } else {
        // Block <50% full → decrease fee
        decrease := delta * (gasTarget - gasUsed) / gasTarget
        return parentBaseFee - decrease
    }
}
```

***

### Model 3: Dynamic Fees (Research Phase)

```
Fee = f(Network Congestion, Block Space, Validator Demand)

Factors:
├─ Mempool size:       High mempool → higher base fee
├─ Block utilization:  >80% full → increase fees
├─ Time of day:        Peak hours → surge pricing
└─ Validator count:    More validators → lower fees
```

**Example Dynamic Pricing:**

```
Low Congestion (10% mempool):
├─ Base fee: 5 Gwei
└─ Priority: 1 Gwei
└─ Total: ~0.000126 QWING per TX

High Congestion (90% mempool):
├─ Base fee: 50 Gwei
└─ Priority: 10 Gwei
└─ Total: ~0.00126 QWING per TX (10x higher)
```

***

## QWVM Gas Metering

### WebAssembly Instruction Costs

**Metering Example:**

```rust
// QWVM contract (Rust → WASM)
pub fn transfer(to: Address, amount: u128) -> Result<(), Error> {
    // Gas costs for this function:
    let sender = get_caller();           // 100 gas
    let balance = storage_read(sender);  // 20,000 gas (SLOAD)
    
    if balance < amount {                // 3 gas (comparison)
        return Err(Error::InsufficientFunds);
    }
    
    storage_write(sender, balance - amount);  // 20,000 gas (SSTORE)
    storage_write(to, balance + amount);      // 20,000 gas (SSTORE)
    
    emit_event("Transfer", sender, to, amount); // 5,000 gas
    
    Ok(())
}

// Total gas: ~65,103 gas
```

**QWVM Opcode Costs:**

| Operation                 | Gas Cost | Reason                  |
| ------------------------- | -------- | ----------------------- |
| `WADD` (addition)         | 3        | Simple arithmetic       |
| `WMUL` (multiply)         | 5        | More complex            |
| `WSLOAD` (storage read)   | 20,000   | Disk I/O                |
| `WSSTORE` (storage write) | 20,000   | Disk I/O + state change |
| `WCALL` (contract call)   | 10,000   | Cross-contract          |
| `WDILITHIUM_VERIFY`       | 0        | **FREE** (quantum-safe) |
| `WLOG` (emit event)       | 5,000    | Log storage             |

***

## Validator Revenue Examples

### Low Activity Scenario

```
Network: Month 1 (10 TPS average)
├─ Transactions per day: 864,000
├─ Transactions per block: 120
├─ Gas per TX: 21,000
├─ Gas price: 10 Gwei
├─ Blocks per day: 7,200

Daily Validator Earnings:
├─ Per block: 120 TX × 21,000 × 10 Gwei = 0.0252 QWING
├─ Per day: 0.0252 QWING × 7,200 blocks = 181.44 QWING
└─ Per validator (3 total): 60.48 QWING/day

Monthly (30 days):
└─ 1,814 QWING per validator
```

***

### High Activity Scenario

```
Network: Month 12 (146 TPS peak)
├─ Transactions per day: 12,624,205
├─ Transactions per block: 1,753
├─ Gas per TX: 21,000
├─ Gas price: 10 Gwei
├─ Blocks per day: 7,200

Daily Validator Earnings:
├─ Per block: 1,753 TX × 21,000 × 10 Gwei = 0.3681 QWING
├─ Per day: 0.3681 QWING × 7,200 blocks = 2,650 QWING
└─ Per validator (3 total): 883 QWING/day

Monthly (30 days):
└─ 26,500 QWING per validator
```

***

## Comparison with Other Chains

### Gas Price Comparison

| Blockchain       | Avg Gas Price | Simple Transfer Cost     | Notes                        |
| ---------------- | ------------- | ------------------------ | ---------------------------- |
| **QuantumWing**  | **10 Gwei**   | **0.00021 QWING**        | Quantum-safe, Dilithium FREE |
| Ethereum Mainnet | 30-100 Gwei   | 0.00063-0.0021 ETH       | High congestion              |
| Arbitrum (L2)    | 0.1-1 Gwei    | 0.0000021-0.000021 ETH   | Cheaper L2                   |
| Polygon          | 30-100 Gwei   | 0.00063-0.0021 MATIC     | Similar to ETH               |
| Solana           | N/A           | 0.000005 SOL (\~$0.0002) | Different model              |
| Bitcoin          | N/A           | \~$1-5 (10 sat/vB)       | UTXO model                   |

**Competitive Positioning:**

* QuantumWing at **10 Gwei** is cheaper than Ethereum mainnet
* More expensive than L2s (Arbitrum), but offers L1 security + quantum-safety
* Comparable to Polygon/BSC pricing

***

## Cost Optimization Tips

### For Users

**1. Choose Optimal Gas Price**

```bash
# Check current network gas price
$ quantum-wing gas-price
Current: 10 Gwei (standard)
Suggest: 8 Gwei (low), 15 Gwei (fast)

# Use low gas for non-urgent transactions
$ quantum-wing send --to 0xABC... --amount 1 --gas-price 8gwei
```

**2. Batch Transactions**

```bash
# Send multiple transfers in one block (saves overhead)
$ quantum-wing batch-send --recipients recipients.csv --gas-price 10gwei

# Instead of:
# 10 TX × 21,000 gas = 210,000 gas
# Batch overhead: ~5,000 gas
# Total: 215,000 gas (saves 2.4%)
```

**3. Off-Peak Hours**

```
Low activity times (if dynamic pricing):
├─ Night (UTC 00:00-06:00): 20% cheaper
├─ Weekends: 15% cheaper
└─ Holidays: 30% cheaper
```

***

### For Developers

**1. Optimize Contract Code**

```rust
// ❌ Bad: Multiple storage reads
pub fn get_balance(addr: Address) -> u128 {
    let balances = storage_read("balances");  // 20K gas
    balances.get(addr)                         // 20K gas
}

// ✅ Good: Cache in memory
pub fn get_balance(addr: Address) -> u128 {
    let balances = BALANCES.get();  // Cached, 100 gas
    balances.get(addr)
}
```

**2. Use Events Instead of Storage**

```rust
// ❌ Expensive: Store every transfer
storage_write("transfer_history", history);  // 20K gas per transfer

// ✅ Cheaper: Emit events
emit_event("Transfer", from, to, amount);    // 5K gas
// Users can query event logs instead
```

**3. Batch Operations**

```rust
// ❌ Loop writes (N × 20K gas)
for recipient in recipients {
    storage_write(recipient, amount);
}

// ✅ Merkle tree (log(N) writes)
let root = compute_merkle_root(recipients);
storage_write("merkle_root", root);  // 20K gas once
```

***

## Future Considerations

### Potential Improvements

**1. Gas Refunds**

```
Idea: Refund gas when storage is freed
├─ Delete storage slot: Refund 15,000 gas
├─ Self-destruct contract: Refund 24,000 gas
└─ Incentivizes cleanup
```

**2. Gas Tokens**

```
Concept: Users buy gas in bulk when cheap
├─ Buy: Store gas as contract state when low price
├─ Use: Burn stored gas when price is high
└─ Arbitrage opportunity
```

**3. Gasless Transactions (Meta-TX)**

```
Model: Relayer pays gas, user pays in tokens
├─ User signs transaction (0 QWING balance)
├─ Relayer submits + pays gas
├─ Contract deducts token from user
└─ Better UX for new users
```

***

## Testing Gas Costs

### Development Tools

```bash
# 1. Estimate gas before sending
$ quantum-wing gas-estimate \
    --to 0xContractAddress \
    --data 0x... \
    --from 0xYourAddress

Estimated gas: 152,341
Recommended limit: 182,809 (20% buffer)

# 2. Dry-run transaction
$ quantum-wing send \
    --to 0xABC... \
    --amount 1 \
    --gas-price 10gwei \
    --dry-run

Simulation result:
✅ Success
Gas used: 21,000 / 21,000
Cost: 0.00021 QWING

# 3. Analyze contract gas usage
$ quantum-wing contract analyze counter.wasm
Function: increment()
├─ Storage reads: 1 (20K gas)
├─ Storage writes: 1 (20K gas)
├─ Computation: 120 gas
└─ Total: 40,120 gas
```

***

## Summary

**Key Points:**

1. ✅ **Gas Model**: EVM-compatible, quantum-safe
2. ✅ **Simple Transfer**: 21,000 gas (\~0.00021 QWING at 10 Gwei)
3. ✅ **Dilithium Verification**: FREE (0 gas)
4. ✅ **Block Limit**: 30M gas (up to 1,428 simple transfers)
5. ✅ **Fee Distribution**: Legacy (100% to proposer) + EIP-1559 Type-2 (base fee burned)
6. 📊 **Pricing**: Competitive with Ethereum L1, more than L2s
7. ✅ **EIP-1559**: Shipped — dynamic base fee + priority tip (see [eip1559.md](/quantumwing/transactions/eip1559.md))

{% hint style="warning" %}
**Note:** Final gas pricing, fee distribution model, and economic parameters are still being finalized. Examples use 10 Gwei baseline for illustration purposes.
{% endhint %}

***

*Last Updated: June 2026*\
*Status: Examples and models under evaluation*


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://quantumwing.gitbook.io/quantumwing/transactions/gas-fees.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
