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.
Parameters
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"
}'import axios from 'axios';
const url = 'https://go.getblock.io/<ACCESS-TOKEN>/';
const payload = {
jsonrpc: '2.0',
method: 'eth_gasPrice',
params: [],
id: 'getblock.io'
};
axios.post(url, payload, {
headers: { 'Content-Type': 'application/json' }
})
.then(response => {
const gasPriceWei = parseInt(response.data.result, 16);
const gasPriceGwei = gasPriceWei / 1e9;
console.log(`Gas Price: ${gasPriceGwei} Gwei`);
})
.catch(error => console.error(error));Response
{
"jsonrpc": "2.0",
"id": "getblock.io",
"result": "0x6FC23AC00"
}Response parameters
Field
Type
Description
Use case
Example: Transaction Cost Calculator
Error handling
Status Code
Error Message
Cause
Web3 integration
Last updated
Was this helpful?