Cronos 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.
Get you own node endpoint today
Start for free and get your app to production levels immediately. No credit card required.
You can sign up with your GitHub, X, Google, or Microsoft account.
Parameters
none
Response
quantity
— the estimated priority fee per gas needed, represented as a hexadecimal string.
eth_maxPriorityFeePerGas
code examples
eth_maxPriorityFeePerGas
code examplesconst { Web3, Web3PluginBase } = require("web3");
const NODE_URL = "CHAINSTACK_NODE_URL";
const web3 = new Web3(NODE_URL);
// Define the MaxPriorityFeePerGas class
class MaxPriorityFeePerGas extends Web3PluginBase {
pluginNamespace = 'ethFee';
async getMaxPriorityFeePerGas() {
return this.requestManager.send({
method: 'eth_maxPriorityFeePerGas',
params: [],
});
}
}
// Register the plugin with Web3
web3.registerPlugin(new MaxPriorityFeePerGas());
// Function to get the max priority fee per gas using the custom plugin
async function getMaxPriorityFeePerGas() {
try {
const maxPriorityFeePerGas = await web3.ethFee.getMaxPriorityFeePerGas();
console.log(`Estimated max priority fee per gas: ${maxPriorityFeePerGas}`);
} catch (error) {
console.error("Error fetching max priority fee per gas:", error);
}
}
// Call the function
getMaxPriorityFeePerGas();
const ethers = require('ethers');
const NODE_URL = "CHAINSTACK_NODE_URL";
const provider = new ethers.JsonRpcProvider(NODE_URL);
const estimatePriorityFee = async () => {
const priorityFeePerGas = await provider.getFeeData();
console.log(`Estimated priority fee per gas: ${priorityFeePerGas.maxPriorityFeePerGas}`);
};
estimatePriorityFee();
const { Web3 } = require("web3");
const NODE_URL = "CHAINSTACK_NODE_URL";
const web3 = new Web3(NODE_URL);
eth_max_priority_fee_per_gas = web3.make_request('eth_maxPriorityFeePerGas', [])
print(eth_max_priority_fee_per_gas)
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 promptly 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.
Try the eth_maxPriorityFeePerGas
RPC method yourself
eth_maxPriorityFeePerGas
RPC method yourself