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.
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
Property | Type | Description |
---|---|---|
Promise<number> | number | Returns 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
yarn add alchemy-sdk
Request
// Imports the Alchemy SDK
const { Alchemy, Network } = require("alchemy-sdk");
// Configures the Alchemy SDK
const config = {
apiKey: "alchemy-replit", // Replace with your API key
network: Network.ETH_MAINNET, // Replace with your network
};
// Creates an Alchemy object instance with the config to use for making requests
const alchemy = new Alchemy(config);
const main = async () => {
//Call the method to display the max priority fee per gas in wei
const response = await alchemy.transact.getMaxPriorityFeePerGas()
//Logging the response to the console
console.log(response)
}
main();
Response
94000000
Code Sandbox
You can test out the getMaxPriorityFeePerGas
method using the code sandbox below:
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.