eth_gasPrice - Somnia
This method returns the current gas price on the Somnia network in wei. Somnia features dynamic gas pricing with sub-cent transaction fees, making it highly economical for high-throughput applications. This method is essential for estimating transaction costs and setting appropriate gas prices.
Parameters
- None
Returns
| Field | Type | Description |
|---|---|---|
| result | string | Current gas price in wei as hexadecimal |
Request Example
cURL
bashcurl -X POST https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/ \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": "getblock.io",
"method": "eth_gasPrice",
"params": []
}'JavaScript (Axios)
javascriptconst axios = require('axios');
const url = 'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/';
const payload = {
jsonrpc: '2.0',
id: 'getblock.io',
method: 'eth_gasPrice',
params: []
};
axios.post(url, payload, {
headers: { 'Content-Type': 'application/json' }
})
.then(response => console.log(response.data))
.catch(error => console.error(error));Python
pythonimport requests
import json
url = "https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/"
payload = {
"jsonrpc": "2.0",
"id": "getblock.io",
"method": "eth_gasPrice",
"params": []
}
response = requests.post(url, headers={"Content-Type": "application/json"}, json=payload)
print(response.json())Rust
rustuse reqwest::Client;
use serde_json::json;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::new();
let payload = json!({
"jsonrpc": "2.0",
"id": "getblock.io",
"method": "eth_gasPrice",
"params": []
});
let response = client
.post("https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/")
.header("Content-Type", "application/json")
.json(&payload)
.send()
.await?;
let result: serde_json::Value = response.json().await?;
println!("{:#?}", result);
Ok(())
}Response Example
json{
"jsonrpc": "2.0",
"id": "getblock.io",
"result": "0x3b9aca00"
}Response Parameters
| Parameter | Type | Description |
|---|---|---|
| result | string | Gas price in wei (0x3b9aca00 = 1 Gwei) |
Use Cases
- Estimate transaction costs
- Set appropriate gas prices for transactions
- Monitor network congestion
- Calculate fee budgets for dApps
- Implement gas price strategies
Error Handling
| Error Code | Description |
|---|---|
| -32603 | Internal error - node processing issues |
| -32000 | Server error - RPC endpoint unavailable |
SDK Integration
Ethers.js
javascriptconst { ethers } = require('ethers');
const provider = new ethers.JsonRpcProvider('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/');
const gasPrice = await provider.getFeeData();
console.log(ethers.formatUnits(gasPrice.gasPrice, 'gwei')); // Convert to GweiViem
javascriptimport { createPublicClient, http, formatGwei } from 'viem';
import { somnia } from 'viem/chains';
const client = createPublicClient({
chain: somnia,
transport: http('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/')
});
const gasPrice = await client.getGasPrice();
console.log(formatGwei(gasPrice));