eth_gasPrice - Base

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

bashcurl --location --request POST 'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "jsonrpc": "2.0",
    "method": "eth_gasPrice",
    "params": [],
    "id": "getblock.io"
}'
javascriptconst axios = require('axios');

const response = await axios.post('https://shared.eu-central-1.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');
pythonimport requests

response = requests.post(
    'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/',
    headers={'Content-Type': 'application/json'},
    json={
        'jsonrpc': '2.0',
        'method': 'eth_gasPrice',
        'params': [],
        'id': 'getblock.io'
    }
)

result = response.json()
gas_price_wei = int(result['result'], 16)
gas_price_gwei = gas_price_wei / 1e9
print(f'Gas Price: {gas_price_gwei} gwei')
rustuse reqwest::Client;
use serde_json::{json, Value};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new();
    
    let response = client
        .post("https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/")
        .header("Content-Type", "application/json")
        .json(&json!({
            "jsonrpc": "2.0",
            "method": "eth_gasPrice",
            "params": [],
            "id": "getblock.io"
        }))
        .send()
        .await?
        .json::<Value>()
        .await?;
    
    println!("Gas Price: {}", response["result"]);
    Ok(())
}

Response

json{
    "jsonrpc": "2.0",
    "id": "getblock.io",
    "result": "0x5f5e100"
}

Response Parameters

ParameterTypeDescription
jsonrpcstringJSON-RPC protocol version ("2.0")
idstringRequest identifier matching the request
resultstringHexadecimal 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

Error CodeMessageDescription
-32603Internal errorNode internal failure
-32600Invalid requestMalformed JSON-RPC request

Web3 Integration

javascriptconst { ethers } = require('ethers');

const provider = new ethers.JsonRpcProvider('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/');

async function getGasPrice() {
    const feeData = await provider.getFeeData();
    
    console.log('Gas Price:', ethers.formatUnits(feeData.gasPrice, 'gwei'), 'gwei');
    console.log('Max Fee Per Gas:', ethers.formatUnits(feeData.maxFeePerGas, 'gwei'), 'gwei');
    console.log('Max Priority Fee:', ethers.formatUnits(feeData.maxPriorityFeePerGas, 'gwei'), 'gwei');
    
    return feeData;
}

getGasPrice();
javascriptimport { createPublicClient, http, formatGwei } from 'viem';
import { base } from 'viem/chains';

const client = createPublicClient({
    chain: base,
    transport: http('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/')
});

async function getGasPrice() {
    const gasPrice = await client.getGasPrice();
    console.log('Gas Price:', formatGwei(gasPrice), 'gwei');
    return gasPrice;
}

getGasPrice();