The eth_gasPrice
method returns the current gas price in wei. This value represents the median gas price from recent blocks, providing developers with a reliable baseline for transaction fee calculations and helping users avoid transaction failures due to low gas prices.
This method provides a simple way to query the current network gas price. It requires no parameters and returns a single hexadecimal value representing the gas price in wei.
Current gas price in wei (hexadecimal)
{
"jsonrpc": "2.0",
"id": 1,
"result": "0x1DCD65000" // 8 Gwei
}
Gas prices are typically discussed in these units:
For user interfaces, converting the returned value to Gwei usually provides a more readable format. For example, 0x1DCD65000
(8 Gwei) is easier to understand than 8,000,000,000 wei.
// Example of calculating gas cost for a standard transfer
const gasPrice = await provider.send('eth_gasPrice', []);
const gasPriceInGwei = parseInt(gasPrice, 16) / 1e9;
const standardTransferGas = 21000;
const costInEth = (parseInt(gasPrice, 16) * standardTransferGas) / 1e18;
eth_feeHistory
to determine appropriate maxFeePerGas
and maxPriorityFeePerGas
values