> ## Documentation Index
> Fetch the complete documentation index at: https://sidiorresearchlabs.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Transaction Gas Parameters

> Learn how to set optimal gas parameters for your transactions on HyperPaxeer

## Overview

Setting the right gas parameters ensures your transactions are processed efficiently and cost-effectively on HyperPaxeer.

## Gas Parameters

EIP-1559 transactions on HyperPaxeer use these gas parameters:

**gasLimit** `uint256` *required*

Maximum amount of gas you're willing to consume

**maxFeePerGas** `uint256` *required*

Maximum total gas price you're willing to pay (base + priority)

**maxPriorityFeePerGas** `uint256` *required*

Maximum tip you're willing to pay to the sequencer

## Setting Gas Limit

The gas limit is the maximum amount of gas your transaction can consume.

### Best Practices

> [accordion] Estimate First
>
> Always estimate gas before setting the limit:
>
> ```javascript theme={null}
> const gasEstimate = await provider.estimateGas(tx);
> const gasLimit = gasEstimate * 120n / 100n; // Add 20% buffer
> ```

> [accordion] Add a Buffer
>
> Add 10-20% buffer to handle minor variations:
>
> | Transaction Type | Recommended Buffer |
> | - | - |
> | Simple transfers | 10% |
> | Token transfers | 15% |
> | Complex contracts | 20% |
> | DeFi interactions | 25% |

> [accordion] Don't Over-estimate
>
> While unused gas is refunded, setting the limit too high:
>
> * Requires more HPX in your wallet upfront
> * May trigger wallet warnings
> * Can indicate poorly optimized contracts

### Common Gas Limits

| Operation | Typical Gas | With Buffer |
| - | - | - |
| ETH transfer | 21,000 | 25,000 |
| ERC-20 transfer | 65,000 | 78,000 |
| ERC-20 approve | 45,000 | 54,000 |
| Uniswap swap | 150,000 | 180,000 |
| NFT mint | 200,000 | 240,000 |

## Setting Max Fee Per Gas

The `maxFeePerGas` is the absolute maximum you're willing to pay per gas unit.

### Recommended Strategy

**1. Get Current Base Fee**

```javascript theme={null}
const feeData = await provider.getFeeData();
const currentBaseFee = feeData.maxFeePerGas - feeData.maxPriorityFeePerGas;
```

**2. Add Buffer for Base Fee Increases**

```javascript theme={null}
// Base fee can increase up to 12.5% per block
// For 5 blocks safety: 1.125^5 ≈ 1.8
const maxBaseFee = currentBaseFee * 2n; // 100% buffer
```

**3. Add Priority Fee**

```javascript theme={null}
const priorityFee = feeData.maxPriorityFeePerGas;
const maxFeePerGas = maxBaseFee + priorityFee;
```

### Example Implementation

```javascript theme={null}
async function calculateOptimalMaxFee() {
  const feeData = await provider.getFeeData();
  
  // Current fees
  const currentBaseFee = feeData.maxFeePerGas - feeData.maxPriorityFeePerGas;
  const priorityFee = feeData.maxPriorityFeePerGas;
  
  // Add 100% buffer to base fee
  const maxBaseFee = currentBaseFee * 2n;
  
  // Calculate max fee per gas
  const maxFeePerGas = maxBaseFee + priorityFee;
  
  return {
    maxFeePerGas,
    maxPriorityFeePerGas: priorityFee,
  };
}

// Usage
const fees = await calculateOptimalMaxFee();
const tx = await signer.sendTransaction({
  to: '0x...',
  value: ethers.parseEther('1.0'),
  maxFeePerGas: fees.maxFeePerGas,
  maxPriorityFeePerGas: fees.maxPriorityFeePerGas,
});
```

## Setting Priority Fee

The priority fee (tip) incentivizes the sequencer to include your transaction faster.

### Priority Levels

> [tab] Low Priority
>
> **When to use:** Non-urgent transactions
>
> ```javascript theme={null}
> const priorityFee = 0n; // or 1 gwei minimum
> ```
>
> * **Speed:** May take several blocks
> * **Cost:** Minimal
> * **Use case:** Batch operations, non-time-sensitive transfers

> [tab] Standard Priority
>
> **When to use:** Normal transactions
>
> ```javascript theme={null}
> const priorityFee = await provider.send('eth_maxPriorityFeePerGas', []);
> ```
>
> * **Speed:** Usually next block
> * **Cost:** Average
> * **Use case:** Regular transfers, most dApp interactions

> [tab] High Priority
>
> **When to use:** Urgent transactions
>
> ```javascript theme={null}
> const recommendedFee = await provider.send('eth_maxPriorityFeePerGas', []);
> const priorityFee = BigInt(recommendedFee) * 2n; // 2x recommended
> ```
>
> * **Speed:** Very likely next block
> * **Cost:** Higher
> * **Use case:** MEV protection, arbitrage, time-sensitive operations

## Legacy vs EIP-1559 Transactions

> [tab] EIP-1559 (Recommended)
>
> ### Type 2 Transactions
>
> Modern transaction type with better fee market:
>
> ```javascript theme={null}
> const tx = await signer.sendTransaction({
>   to: '0x...',
>   value: ethers.parseEther('1.0'),
>   maxFeePerGas: ethers.parseUnits('2', 'gwei'),
>   maxPriorityFeePerGas: ethers.parseUnits('1', 'gwei'),
> });
> ```
>
> **Advantages:**
>
> * More predictable fees
> * Better UX (only pay actual base fee)
> * Automatic refunds for overpayment

> [tab] Legacy
>
> ### Type 0 Transactions
>
> Old-style transactions with single gas price:
>
> ```javascript theme={null}
> const tx = await signer.sendTransaction({
>   to: '0x...',
>   value: ethers.parseEther('1.0'),
>   gasPrice: ethers.parseUnits('2', 'gwei'),
> });
> ```
>
> **Note:** Still supported but EIP-1559 is preferred

## Complete Transaction Example

```typescript SendOptimizedTransaction.ts theme={null}
import { ethers } from 'ethers';

async function sendOptimizedTransaction(to: string, value: bigint) {
  const provider = new ethers.JsonRpcProvider('https://public-rpc.paxeer.app/rpc');
  const signer = await provider.getSigner();

  // 1. Estimate gas
  const tx = { to, value };
  const gasEstimate = await provider.estimateGas(tx);
  const gasLimit = gasEstimate * 120n / 100n; // 20% buffer

  // 2. Get fee data
  const feeData = await provider.getFeeData();
  
  // 3. Calculate optimal fees
  const currentBaseFee = feeData.maxFeePerGas - feeData.maxPriorityFeePerGas;
  const maxBaseFee = currentBaseFee * 2n; // 100% buffer
  const priorityFee = feeData.maxPriorityFeePerGas;
  const maxFeePerGas = maxBaseFee + priorityFee;

  // 4. Estimate cost
  const estimatedCost = gasLimit * (currentBaseFee + priorityFee);
  
  console.log('Transaction Details:');
  console.log('- Gas Limit:', gasLimit.toString());
  console.log('- Max Fee:', ethers.formatUnits(maxFeePerGas, 'gwei'), 'gwei');
  console.log('- Priority Fee:', ethers.formatUnits(priorityFee, 'gwei'), 'gwei');
  console.log('- Estimated Cost:', ethers.formatEther(estimatedCost), 'HPX');

  // 5. Send transaction
  const txResponse = await signer.sendTransaction({
    to,
    value,
    gasLimit,
    maxFeePerGas,
    maxPriorityFeePerGas: priorityFee,
  });

  console.log('Transaction sent:', txResponse.hash);
  
  // 6. Wait for confirmation
  const receipt = await txResponse.wait();
  
  // 7. Calculate actual cost
  const actualCost = receipt.gasUsed * receipt.gasPrice;
  console.log('Actual Cost:', ethers.formatEther(actualCost), 'HPX');
  
  return receipt;
}
```

## Network-Specific Considerations

### HyperPaxeer Specifics

| Parameter | Value | Notes |
| - | - | - |
| Average Base Fee | \~1 gwei | Much lower than Ethereum |
| Block Time | 277 ms average | Faster than Ethereum's 12 seconds |
| Block Gas Limit | 30M | Same as Ethereum |
| Max Base Fee Change | 12.5% per block | EIP-1559 standard |

### Fee Estimation Formula

```javascript theme={null}
// Minimum balance needed
const minBalance = (gasLimit × maxFeePerGas) + value;

// Likely actual cost (optimistic)
const likelyCost = (gasLimit × currentBaseFee) + (gasUsed × priorityFee);

// Maximum possible cost (pessimistic)
const maxCost = gasLimit × maxFeePerGas;
```

## Error Prevention

> [!WARNING]
>
> Common mistakes to avoid:
>
> 1. **Setting gasLimit too low** → Transaction fails
> 2. **Setting maxFeePerGas too low** → Transaction stuck in mempool
> 3. **Not adding buffer to estimates** → Transaction may fail
> 4. **Using stale fee data** → Overpaying or stuck transactions

## Next Steps

> [card] [Transaction Fees](https://sidiorresearchlabs.mintlify.site/app-developers/guides/transactions/fees.md)
>
> Understand fee components

> [card] [Cost Estimates](https://sidiorresearchlabs.mintlify.site/app-developers/guides/transactions/estimates.md)
>
> Estimate transaction costs

> [card] [Troubleshooting](https://sidiorresearchlabs.mintlify.site/app-developers/guides/transactions/troubleshooting.md)
>
> Fix transaction issues

> [card] [Examples](https://sidiorresearchlabs.mintlify.site/examples.md)
>
> View code examples


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.