getMaxPriorityFeePerGas - SDK

Returns a fee per gas (in wei) that is an estimate of how much you can pay as a priority fee, or \tip, to get a transaction included in the current block. This number is generally used to set the maxPriorityFeePerGas field in a transaction request.

Returns a fee per gas (in wei) that is an estimate of how much you can pay as a priority fee, or “tip”, to get a transaction included in the current block. This number is generally used to set the maxPriorityFeePerGas field in a transaction request.

Don’t have an API key?

Start using this method in your app today. Get started for free

Description

Returns a fee per gas (in wei) that is an estimate of how much you can pay as a priority fee, or “tip”, to get a transaction included in the current block.

This number is generally used to set the maxPriorityFeePerGas field in a transaction request.

Response

PropertyTypeDescription
Promise<number>numberReturns the fee per gas.

Example Request and Response

Prerequisite: You will need to install the Alchemy SDK before making requests with it.

The commands for installing it using npm or yarn are given below:

$npm install alchemy-sdk

Request

index.js
1// Imports the Alchemy SDK
2const { Alchemy, Network } = require("alchemy-sdk");
3
4// Configures the Alchemy SDK
5const config = {
6 apiKey: "alchemy-replit", // Replace with your API key
7 network: Network.ETH_MAINNET, // Replace with your network
8};
9
10// Creates an Alchemy object instance with the config to use for making requests
11const alchemy = new Alchemy(config);
12
13const main = async () => {
14 //Call the method to display the max priority fee per gas in wei
15 const response = await alchemy.transact.getMaxPriorityFeePerGas()
16
17 //Logging the response to the console
18 console.log(response)
19}
20
21main();

Response

shell
$94000000

Use Cases

Here are some potential use cases for the getMaxPriorityFeePerGas method:

  • Setting optimal gas fees for transactions: By using the getMaxPriorityFeePerGas method, developers can ensure that they are setting optimal gas fees for their transactions. This can help to ensure that transactions are processed quickly and efficiently, while also minimizing costs for users.
  • Automating gas fee calculations: Some applications may need to automatically calculate gas fees for transactions. By using the getMaxPriorityFeePerGas method, developers can automate this process and ensure that gas fees are always set at the optimal level.
  • Monitoring network congestion: The value returned by getMaxPriorityFeePerGas can be an indicator of network congestion. Developers can use this information to monitor the health of the network and adjust their gas fees accordingly.
  • Providing transparency to users: By displaying the current getMaxPriorityFeePerGas value to users, developers can provide transparency and help users make informed decisions about their transactions.