curl --request POST \
--url https://bsc-mainnet.core.chainstack.com/35848e183f3e3303c8cfeacbea831cab \
--header 'Content-Type: application/json' \
--data '{
"id": 1,
"jsonrpc": "2.0",
"method": "eth_maxPriorityFeePerGas",
"params": []
}'
{
"jsonrpc": "<string>",
"id": 123,
"result": "aSDinaTvuI8gbWludGxpZnk="
}
curl --request POST \
--url https://bsc-mainnet.core.chainstack.com/35848e183f3e3303c8cfeacbea831cab \
--header 'Content-Type: application/json' \
--data '{
"id": 1,
"jsonrpc": "2.0",
"method": "eth_maxPriorityFeePerGas",
"params": []
}'
{
"jsonrpc": "<string>",
"id": 123,
"result": "aSDinaTvuI8gbWludGxpZnk="
}
none
quantity
— the estimated priority fee per gas needed, represented as a hexadecimal string.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();
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.The estimated max priority fee per gas
The response is of type object
.
Was this page helpful?