githubEdit

eth_gasPrice - Polygon

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

The eth_gasPrice method returns the current gas price in wei. This value represents the median gas price of the most recent blocks and is useful for estimating transaction costs. On Polygon, gas prices are typically very low compared to Ethereum mainnet.

Parameters

  • None

Request

cURL
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"
}'

Response

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

Response parameters

Field
Type
Description

jsonrpc

string

JSON-RPC version (2.0)

id

string

Request identifier

result

string

Current gas price in wei (hexadecimal)

Use case

The eth_gasPrice method is essential for:

  • Transaction cost calculation: Estimate total cost before sending transactions

  • Gas price monitoring: Track network congestion levels

  • Dynamic pricing: Adjust gas prices based on network conditions

  • Budget management: Ensure sufficient funds for transactions

  • Arbitrage: Monitor gas prices for MEV opportunities

Example: Transaction Cost Calculator

Error handling

Status Code
Error Message
Cause

403

Forbidden

Missing or invalid ACCESS-TOKEN

-32600

Invalid Request

Malformed request body

Web3 integration

Last updated

Was this helpful?