> ## 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:

<ParamField path="gasLimit" type="uint256" required>
  Maximum amount of gas you're willing to consume
</ParamField>

<ParamField path="maxFeePerGas" type="uint256" required>
  Maximum total gas price you're willing to pay (base + priority)
</ParamField>

<ParamField path="maxPriorityFeePerGas" type="uint256" required>
  Maximum tip you're willing to pay to the sequencer
</ParamField>

## Setting Gas Limit

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

### Best Practices

<AccordionGroup>
  <Accordion title="Estimate First" icon="calculator">
    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>

  <Accordion title="Add a Buffer" icon="shield">
    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>

  <Accordion title="Don't Over-estimate" icon="ban">
    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
  </Accordion>
</AccordionGroup>

### 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

<Steps>
  <Step title="Get Current Base Fee">
    ```javascript theme={null}
    const feeData = await provider.getFeeData();
    const currentBaseFee = feeData.maxFeePerGas - feeData.maxPriorityFeePerGas;
    ```
  </Step>

  <Step title="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
    ```
  </Step>

  <Step title="Add Priority Fee">
    ```javascript theme={null}
    const priorityFee = feeData.maxPriorityFeePerGas;
    const maxFeePerGas = maxBaseFee + priorityFee;
    ```
  </Step>
</Steps>

### 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

<Tabs>
  <Tab title="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>

  <Tab title="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>

  <Tab title="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
  </Tab>
</Tabs>

## Legacy vs EIP-1559 Transactions

<Tabs>
  <Tab title="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>

  <Tab title="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
  </Tab>
</Tabs>

## 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
</Warning>

## Next Steps

<CardGroup cols={2}>
  <Card title="Transaction Fees" icon="money-bill" href="/app-developers/guides/transactions/fees">
    Understand fee components
  </Card>

  <Card title="Cost Estimates" icon="calculator" href="/app-developers/guides/transactions/estimates">
    Estimate transaction costs
  </Card>

  <Card title="Troubleshooting" icon="wrench" href="/app-developers/guides/transactions/troubleshooting">
    Fix transaction issues
  </Card>

  <Card title="Examples" icon="code" href="/examples">
    View code examples
  </Card>
</CardGroup>
