# eth_maxPriorityFeePerGas - Avalanche RPC Method

Returns the current suggested priority fee (tip) per gas in wei on Avalanche. This is the amount paid directly to validators to incentivize faster transaction inclusion in EIP-1559 compatible blocks.

> **Why Avalanche?** Build on the fastest smart contract platform with sub-second finality and customizable L1 subnets with sub-second finality, Evergreen subnets for institutions, and partnerships with Franklin Templeton, VanEck, and Bergen County.

## When to Use This Method

`eth_maxPriorityFeePerGas` is essential for enterprise developers, RWA tokenizers, and teams building custom blockchain networks:

- **EIP-1559 Transaction Building** - Get the recommended tip to include in `maxPriorityFeePerGas` when constructing type-2 transactions on Avalanche
- **Fee Optimization** - Balance transaction speed against cost by adjusting the priority fee relative to the suggested value
- **Time-Sensitive Transactions** - Increase the tip above the suggested value for DEX swaps, liquidations, or other latency-sensitive operations on institutional RWA tokenization ($18B+ transfer volume), gaming subnets, and enterprise blockchains
- **Gas Price Estimation** - Combine with `baseFeePerGas` from the latest block to calculate the total `maxFeePerGas` for accurate fee estimation

## Request Parameters

This method accepts no parameters.

## Request Example

```json
{
  "jsonrpc": "2.0",
  "method": "eth_maxPriorityFeePerGas",
  "params": [],
  "id": 1
}
```

## Response Fields

- `result` (`QUANTITY, required`): Hexadecimal string representing the suggested priority fee per gas in wei

## Successful Response

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": "0x3B9ACA00"
}
```

## Error Responses

### Error Response

- Code: `-32601`

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "error": {
    "code": -32601,
    "message": "The method eth_maxPriorityFeePerGas does not exist/is not available"
  }
}
```

## Code Examples

cURL
JavaScript
Python
Go

```bash
curl -X POST https://api-avalanche-mainnet-archive.n.dwellir.com/YOUR_API_KEY/ext/bc/C/rpc \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "method": "eth_maxPriorityFeePerGas",
    "params": [],
    "id": 1
  }'
```

```javascript
// Using fetch
const response = await fetch('https://api-avalanche-mainnet-archive.n.dwellir.com/YOUR_API_KEY/ext/bc/C/rpc', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    jsonrpc: '2.0',
    method: 'eth_maxPriorityFeePerGas',
    params: [],
    id: 1
  })
});

const { result } = await response.json();
const priorityFeeWei = BigInt(result);
const priorityFeeGwei = Number(priorityFeeWei) / 1e9;
console.log('Avalanche priority fee:', priorityFeeGwei, 'Gwei');

// Using ethers.js
import { JsonRpcProvider, formatUnits } from 'ethers';

const provider = new JsonRpcProvider('https://api-avalanche-mainnet-archive.n.dwellir.com/YOUR_API_KEY/ext/bc/C/rpc');
const feeData = await provider.getFeeData();
console.log('Max Priority Fee:', formatUnits(feeData.maxPriorityFeePerGas, 'gwei'), 'Gwei');
console.log('Max Fee Per Gas:', formatUnits(feeData.maxFeePerGas, 'gwei'), 'Gwei');
```

```python
import requests

def get_max_priority_fee():
    response = requests.post(
        'https://api-avalanche-mainnet-archive.n.dwellir.com/YOUR_API_KEY/ext/bc/C/rpc',
        json={
            'jsonrpc': '2.0',
            'method': 'eth_maxPriorityFeePerGas',
            'params': [],
            'id': 1
        }
    )
    result = response.json()['result']
    return int(result, 16)

priority_fee_wei = get_max_priority_fee()
priority_fee_gwei = priority_fee_wei / 1e9
print(f'Avalanche priority fee: {priority_fee_gwei} Gwei')

# Using web3.py
from web3 import Web3

w3 = Web3(Web3.HTTPProvider('https://api-avalanche-mainnet-archive.n.dwellir.com/YOUR_API_KEY/ext/bc/C/rpc'))
priority_fee = w3.eth.max_priority_fee
print(f'Max Priority Fee: {w3.from_wei(priority_fee, "gwei")} Gwei')
```

```go
package main

import (
    "context"
    "fmt"
    "log"
    "math/big"

    "github.com/ethereum/go-ethereum/ethclient"
)

func main() {
    client, err := ethclient.Dial("https://api-avalanche-mainnet-archive.n.dwellir.com/YOUR_API_KEY/ext/bc/C/rpc")
    if err != nil {
        log.Fatal(err)
    }

    tip, err := client.SuggestGasTipCap(context.Background())
    if err != nil {
        log.Fatal(err)
    }

    gwei := new(big.Float).Quo(new(big.Float).SetInt(tip), big.NewFloat(1e9))
    fmt.Printf("Avalanche priority fee: %s Gwei\n", gwei.Text('f', 4))
}
```

## Common Use Cases

### 1. Build an EIP-1559 Transaction

Construct a properly priced type-2 transaction on Avalanche:

```javascript
import { JsonRpcProvider, Wallet, parseEther } from 'ethers';

const provider = new JsonRpcProvider('https://api-avalanche-mainnet-archive.n.dwellir.com/YOUR_API_KEY/ext/bc/C/rpc');

async function buildEIP1559Transaction(privateKey, to, valueEth) {
  const wallet = new Wallet(privateKey, provider);

  // Get current fee data
  const feeData = await provider.getFeeData();
  const latestBlock = await provider.getBlock('latest');
  const baseFee = latestBlock.baseFeePerGas;

  // Set maxPriorityFeePerGas from the suggestion
  const maxPriorityFeePerGas = feeData.maxPriorityFeePerGas;

  // maxFeePerGas = 2 * baseFee + maxPriorityFeePerGas (buffer for base fee increases)
  const maxFeePerGas = baseFee * 2n + maxPriorityFeePerGas;

  const tx = await wallet.sendTransaction({
    to,
    value: parseEther(valueEth),
    type: 2,
    maxPriorityFeePerGas,
    maxFeePerGas
  });

  console.log('Sent with priority fee:', Number(maxPriorityFeePerGas) / 1e9, 'Gwei');
  return tx;
}
```

### 2. Dynamic Fee Strategy

Adjust priority fees based on transaction urgency:

```javascript
async function getFeeByUrgency(provider, urgency = 'standard') {
  const feeData = await provider.getFeeData();
  const basePriorityFee = feeData.maxPriorityFeePerGas;

  const multipliers = {
    low: 0.8,       // Willing to wait
    standard: 1.0,  // Normal speed
    fast: 1.5,      // Faster inclusion
    urgent: 2.0     // Next-block target
  };

  const multiplier = multipliers[urgency] || 1.0;
  const adjustedFee = BigInt(Math.ceil(Number(basePriorityFee) * multiplier));

  const block = await provider.getBlock('latest');
  const maxFeePerGas = block.baseFeePerGas * 2n + adjustedFee;

  return {
    maxPriorityFeePerGas: adjustedFee,
    maxFeePerGas
  };
}

// Usage
const fees = await getFeeByUrgency(provider, 'fast');
console.log('Priority fee:', Number(fees.maxPriorityFeePerGas) / 1e9, 'Gwei');
console.log('Max fee:', Number(fees.maxFeePerGas) / 1e9, 'Gwei');
```

### 3. Priority Fee Monitor

Track priority fee changes over time on Avalanche:

```javascript
async function monitorPriorityFee(provider, interval = 12000) {
  let previousFee = null;

  setInterval(async () => {
    const feeData = await provider.getFeeData();
    const currentFee = feeData.maxPriorityFeePerGas;
    const feeGwei = Number(currentFee) / 1e9;

    if (previousFee !== null) {
      const change = Number(currentFee - previousFee) / Number(previousFee) * 100;
      const direction = change > 0 ? 'UP' : change < 0 ? 'DOWN' : 'STABLE';
      console.log(`Priority fee: ${feeGwei.toFixed(4)} Gwei (${direction} ${Math.abs(change).toFixed(1)}%)`);
    } else {
      console.log(`Priority fee: ${feeGwei.toFixed(4)} Gwei`);
    }

    previousFee = currentFee;
  }, interval);
}
```

## Best Practices

- Use `eth_feeHistory` with percentile rewards for a more accurate priority fee estimate than the node's suggestion alone
- The suggested priority fee is the minimum for timely inclusion -- multiply by 1.5-2x for faster confirmation on congested networks
- Fall back to `eth_gasPrice` if `eth_maxPriorityFeePerGas` returns method not found (-32601) on non-EIP-1559 nodes
- For L2 chains, the priority fee is typically much lower than L1 -- never reuse L1 gas parameters on L2
- Cache with a short TTL (12 seconds, one block time) since priority fees change with each block

## Related Methods

- [`eth_gasPrice`](https://www.dwellir.com/docs/avalanche/eth_gasPrice) - Get the legacy gas price
- [`eth_feeHistory`](https://www.dwellir.com/docs/avalanche/eth_feeHistory) - Get historical fee data for trend analysis
- [`eth_estimateGas`](https://www.dwellir.com/docs/avalanche/eth_estimateGas) - Estimate gas units required for a transaction
- [`eth_getBlockByNumber`](https://www.dwellir.com/docs/avalanche/eth_getBlockByNumber) - Get block details including `baseFeePerGas`
