> ## Documentation Index
> Fetch the complete documentation index at: https://chainstack-docs-polygon-erigon-trace-deprecation.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# eth_maxPriorityFeePerGas

> Ethereum API method that returns an estimate of the current priority fee per gas. eth_maxPriorityFeePerGas on Chainstack via Chainstack.

# `eth_maxPriorityFeePerGas`

Ethereum API method that returns an estimate of the current priority fee per gas. This fee is the tip that users may pay miners,post-merge, to validators on top of the base fee to incentivize the inclusion of their transactions in a block. This method helps users adjust their transaction fees in a dynamic market, ensuring transactions are processed promptly without overpaying.

## Parameters

* `none`

## Response

* `quantity` — the estimated priority fee per gas needed, represented as a hexadecimal string.

## `eth_maxPriorityFeePerGas` code examples

<Note>
  Learn more about the `ChainstackProvider` in `ethers.js`: [ethers ChainstackProvider Documentation](/reference/ethersjs-chainstackprovider).
</Note>

<CodeGroup>
  ```javascript ethers.js theme={null}
  const ethers = require("ethers");

  // Create a ChainstackProvider instance for Ethereum mainnet
  const chainstack = new ethers.ChainstackProvider("mainnet");

  const estimatePriorityFee = async () => {
    const priorityFeePerGas = await chainstack.getFeeData();
    console.log(
      `Estimated priority fee per gas: ${priorityFeePerGas.maxPriorityFeePerGas}`
    );
  };

  estimatePriorityFee();
  ```

  ```python web3.py theme={null}
  from web3 import Web3
  NODE_URL = "CHAINSTACK_NODE_URL"
  web3 = Web3(Web3.HTTPProvider(NODE_URL))

  eth_max_priority_fee_per_gas = web3.provider.make_request('eth_maxPriorityFeePerGas', [])
  print(eth_max_priority_fee_per_gas)
  ```
</CodeGroup>

## Use Case

A practical use case for `eth_maxPriorityFeePerGas` using `ethers.js` is to calculate transaction fees dynamically for applications and wallets to accurately estimate the cost of transactions, especially during periods of high network congestion. This method ensures transactions are confirmed in a timely manner without overpaying. By fetching the current priority fee (`maxPriorityFeePerGas`) and the maximum fee per gas (`maxFeePerGas`), applications can dynamically calculate the total transaction fee required for prompt processing under the current network conditions.

```javascript JavaScript theme={null}
const ethers = require("ethers");

// Create a ChainstackProvider instance for Ethereum mainnet
const chainstack = new ethers.ChainstackProvider("mainnet");

async function simulateTransaction(fromAddress, toAddress, amountEther) {
  const amountWei = ethers.parseEther(amountEther.toString());
  const feeData = await chainstack.getFeeData();
  console.log("Full gas fee data:", feeData);

  const tx = {
    from: fromAddress,
    to: toAddress,
    value: amountWei,
    maxPriorityFeePerGas: feeData.maxPriorityFeePerGas,
    maxFeePerGas: feeData.maxFeePerGas,
  };

  console.log("Simulating transaction:", tx);

  try {
    const estimatedGas = await chainstack.estimateGas(tx);
    console.log(`Estimated gas for transaction: ${estimatedGas.toString()}`);
  } catch (error) {
    console.error(`Error simulating transaction: ${error}`);
  }
}

const fromAddress = "0xae2Fc483527B8EF99EB5D9B44875F005ba1FaE13";
const toAddress = "0xF135B9eD84E0AB08fdf03A744947cb089049bd79";
const amountEther = 1; // Simulating sending 1 Ether for this example

simulateTransaction(fromAddress, toAddress, amountEther);
```

The `simulateTransaction` function showcases how to build a transaction with dynamically calculated fees based on the current network state, including the base and priority fees. This approach provides a more nuanced and accurate method for estimating the total transaction fee, ensuring users pay a fair amount based on real-time network conditions. It simulates the transaction's execution to estimate gas usage without actually broadcasting it to the network, allowing for cost-effective transaction planning and testing. This simulation is particularly useful for applications that require a balance between transaction cost and confirmation speed, providing a comprehensive picture of the fees needed for timely transaction processing.


## OpenAPI

````yaml openapi/ethereum_node_api/gas_data/eth_maxPriorityFeePerGas.json POST /0a9d79d93fb2f4a4b1e04695da2b77a7
openapi: 3.0.0
info:
  title: Chainstack Node API
  version: 1.0.0
  description: This is an API for interacting with a Chainstack node.
servers:
  - url: https://nd-422-757-666.p2pify.com
security: []
paths:
  /0a9d79d93fb2f4a4b1e04695da2b77a7:
    post:
      tags:
        - upload
      summary: eth_maxPriorityFeePerGas
      operationId: maxPriorityFeePerGas
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                id:
                  type: integer
                  default: 1
                jsonrpc:
                  type: string
                  default: '2.0'
                method:
                  type: string
                  default: eth_maxPriorityFeePerGas
                params:
                  type: array
                  default: []
      responses:
        '200':
          description: The estimated max priority fee per gas
          content:
            application/json:
              schema:
                type: object
                properties:
                  jsonrpc:
                    type: string
                  id:
                    type: integer
                  result:
                    type: string
                    format: byte

````