eth_gasPrice - Base
Example code for the eth_gasPrice JSON-RPC method. Complete guide on how to use eth_gasPrice JSON-RPC in GetBlock Web3 documentation.
The eth_gasPrice method returns the current gas price on the Base network in wei. This value represents the L2 execution fee component. Note that Base transactions also incur an L1 data fee for posting transaction data to Ethereum mainnet.
Parameters
None
Request
curl --location --request POST 'https://go.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
"jsonrpc": "2.0",
"method": "eth_gasPrice",
"params": [],
"id": "getblock.io"
}'const axios = require('axios');
const response = await axios.post('https://go.getblock.io/<ACCESS-TOKEN>/', {
jsonrpc: '2.0',
method: 'eth_gasPrice',
params: [],
id: 'getblock.io'
}, {
headers: { 'Content-Type': 'application/json' }
});
const gasPriceWei = parseInt(response.data.result, 16);
const gasPriceGwei = gasPriceWei / 1e9;
console.log('Gas Price:', gasPriceGwei, 'gwei');Response
{
"jsonrpc": "2.0",
"id": "getblock.io",
"result": "0x5f5e100"
}Response Parameters
jsonrpc
string
JSON-RPC protocol version ("2.0")
id
string
Request identifier matching the request
result
string
Hexadecimal gas price in wei
Use Cases
Transaction Fee Estimation: Calculate L2 execution costs before sending transactions
Gas Price Monitoring: Track network congestion and fee trends
Cost Optimization: Time transactions for lower fees during quiet periods
User Interface Display: Show current gas prices to users
Trading Bot Configuration: Set gas price limits for automated trading
Error Handling
-32603
Internal error
Node internal failure
-32600
Invalid request
Malformed JSON-RPC request
Web3 Integration
Last updated
Was this helpful?