For the complete documentation index, see llms.txt. This page is also available as Markdown.

eth_gasPrice - Optimism

Example code for the eth_gasPrice json-rpc method. Сomplete guide on how to use eth_gasPrice json-rpc in GetBlock.io Web3 documentation.

This method gets the current average gas price. This value is derived from recent transactions and can be used as a baseline for setting transaction fees.

Parameters

  • None

Request

curl --location 'https://shared.us-east-1.getblock.io/<ACCESS_TOKEN>' \
--header 'Content-Type: application/json' \
--data '{
  "jsonrpc": "2.0",
  "method": "eth_gasPrice",
  "id": "getblock.io",
  "params": [],
}'
import axios from 'axios'
let data = JSON.stringify({
  "jsonrpc": "2.0",
  "method": "eth_gasPrice",
  "id": "getblock.io",
  "params": [],
};

let config = {
  method: "post",
  maxBodyLength: Infinity,
  url: "https://shared.us-east-1.getblock.io/<ACCESS_TOKEN>",
  headers: {
    "Content-Type": "application/json",
  },
  data: data,
};

axios
  .request(config)
  .then((response) => {
    console.log(JSON.stringify(response.data));
  })
  .catch((error) => {
    console.log(error);
  });

Response

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

Reponse Parameter Definition

Field
Type
Description

result

string (hex)

Current average gas price in wei

Use case

The eth_gasPrice method is commonly used for:

  • Transaction fee estimation

  • Gas price monitoring

  • DApp transaction management

  • Cost optimization

Error handling

Status Code
Error Message
Cause

404

Not Found

Missing or invalid ACCESS_TOKEN.

Integration with Web3

The eth_gasPrice can help developers:

  • Display real-time gas prices in interfaces

  • Adjust transaction fees automatically

Last updated

Was this helpful?