eth_gasPrice
curl --request POST \
--url https://nd-418-459-126.p2pify.com/8763cb5a211e1d4345acd51bde484c00/ext/bc/C/rpc \
--header 'Content-Type: application/json' \
--data '
{
"id": 1,
"jsonrpc": "2.0",
"method": "eth_gasPrice",
"params": []
}
'import requests
url = "https://nd-418-459-126.p2pify.com/8763cb5a211e1d4345acd51bde484c00/ext/bc/C/rpc"
payload = {
"id": 1,
"jsonrpc": "2.0",
"method": "eth_gasPrice",
"params": []
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({id: 1, jsonrpc: '2.0', method: 'eth_gasPrice', params: []})
};
fetch('https://nd-418-459-126.p2pify.com/8763cb5a211e1d4345acd51bde484c00/ext/bc/C/rpc', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://nd-418-459-126.p2pify.com/8763cb5a211e1d4345acd51bde484c00/ext/bc/C/rpc",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'id' => 1,
'jsonrpc' => '2.0',
'method' => 'eth_gasPrice',
'params' => [
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://nd-418-459-126.p2pify.com/8763cb5a211e1d4345acd51bde484c00/ext/bc/C/rpc"
payload := strings.NewReader("{\n \"id\": 1,\n \"jsonrpc\": \"2.0\",\n \"method\": \"eth_gasPrice\",\n \"params\": []\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://nd-418-459-126.p2pify.com/8763cb5a211e1d4345acd51bde484c00/ext/bc/C/rpc")
.header("Content-Type", "application/json")
.body("{\n \"id\": 1,\n \"jsonrpc\": \"2.0\",\n \"method\": \"eth_gasPrice\",\n \"params\": []\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://nd-418-459-126.p2pify.com/8763cb5a211e1d4345acd51bde484c00/ext/bc/C/rpc")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"id\": 1,\n \"jsonrpc\": \"2.0\",\n \"method\": \"eth_gasPrice\",\n \"params\": []\n}"
response = http.request(request)
puts response.read_body{
"jsonrpc": "<string>",
"id": 123,
"result": "<string>"
}Avalanche node API
eth_gasPrice | Avalanche
Avalanche API method that returns the current gas base fee of the network. Reference for eth_gasPrice on Avalanche via Chainstack.
POST
/
8763cb5a211e1d4345acd51bde484c00
/
ext
/
bc
/
C
/
rpc
eth_gasPrice
curl --request POST \
--url https://nd-418-459-126.p2pify.com/8763cb5a211e1d4345acd51bde484c00/ext/bc/C/rpc \
--header 'Content-Type: application/json' \
--data '
{
"id": 1,
"jsonrpc": "2.0",
"method": "eth_gasPrice",
"params": []
}
'import requests
url = "https://nd-418-459-126.p2pify.com/8763cb5a211e1d4345acd51bde484c00/ext/bc/C/rpc"
payload = {
"id": 1,
"jsonrpc": "2.0",
"method": "eth_gasPrice",
"params": []
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({id: 1, jsonrpc: '2.0', method: 'eth_gasPrice', params: []})
};
fetch('https://nd-418-459-126.p2pify.com/8763cb5a211e1d4345acd51bde484c00/ext/bc/C/rpc', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://nd-418-459-126.p2pify.com/8763cb5a211e1d4345acd51bde484c00/ext/bc/C/rpc",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'id' => 1,
'jsonrpc' => '2.0',
'method' => 'eth_gasPrice',
'params' => [
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://nd-418-459-126.p2pify.com/8763cb5a211e1d4345acd51bde484c00/ext/bc/C/rpc"
payload := strings.NewReader("{\n \"id\": 1,\n \"jsonrpc\": \"2.0\",\n \"method\": \"eth_gasPrice\",\n \"params\": []\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://nd-418-459-126.p2pify.com/8763cb5a211e1d4345acd51bde484c00/ext/bc/C/rpc")
.header("Content-Type", "application/json")
.body("{\n \"id\": 1,\n \"jsonrpc\": \"2.0\",\n \"method\": \"eth_gasPrice\",\n \"params\": []\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://nd-418-459-126.p2pify.com/8763cb5a211e1d4345acd51bde484c00/ext/bc/C/rpc")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"id\": 1,\n \"jsonrpc\": \"2.0\",\n \"method\": \"eth_gasPrice\",\n \"params\": []\n}"
response = http.request(request)
puts response.read_body{
"jsonrpc": "<string>",
"id": 123,
"result": "<string>"
}Avalanche API method that returns the current gas base fee of the network. The gas price is the quantity of the native token the transaction’s sender must pay per unit of gas consumed. The value returned is in Wei.
The following script calculates the total fee to send with a transaction based on the base fee and an arbitrary priority fee that the user can choose.
The
Get your own node endpoint todayStart for free and get your app to production levels immediately. No credit card required.You can sign up with your GitHub, X, Google, or Microsoft account.
Parameters
none
Response
quantity— the integer value of the current gas base fee, returned in Wei
eth_gasPrice code examples
const ethers = require('ethers');
const NODE_URL = "CHAINSTACK_NODE_URL";
const provider = new ethers.JsonRpcProvider(NODE_URL);
async function getGasPrice() {
const baseFee = await provider.send("eth_gasPrice");
console.log(`The base gas fee is: ${baseFee} Wei`);
}
getGasPrice()
from web3 import Web3
node_url = "CHAINSTACK_NODE_URL"
web3 = Web3(Web3.HTTPProvider(node_url))
print(web3.eth.gas_price)
Use case
You can useeth_gasPrice to calculate the total gas value to send with a transaction based on the base and priority fee system. This concept was implemented with EIP-1559 in Ethereum’s London hard fork.
EIP-1559 aimed to solve the problem of network congestion by implementing a dynamic fee market mechanism, which adjusts the fee required to process a transaction based on network demand. with the current system, the total gas price is composed of a base fee determined by the network’s load and a priority fee added by the user.
NoteThe
eth_gasPrice method returns the base fee.index.js
const ethers = require('ethers');
const NODE_URL = "CHAINSTACK_NODE_URL";
const provider = new ethers.JsonRpcProvider(NODE_URL);
async function getGas(priorityFee) {
const priorityFeeWei = ethers.parseUnits(String(priorityFee), 'gwei');
const baseFee = (await provider.getFeeData()).gasPrice;
const totalFee = priorityFeeWei + baseFee
return [totalFee, baseFee]
}
async function main() {
// The priority fee is constant at 2 nAVAX, the user can change it.
const PRIORITY_FEE = 2;
const [totalFee, baseFee] = await getGas(PRIORITY_FEE)
const baseFeeGwei = ethers.formatUnits(baseFee, 'gwei')
console.log(`The priority fee: ${PRIORITY_FEE} nAVAX.`)
console.log(`The Avalanche base fee at this moment is: ${Number(baseFeeGwei).toFixed(2)} nAVAX.`)
const gweiFee = ethers.formatUnits(totalFee, 'gwei')
console.log(`The total gas fee should be at least: ${Number(gweiFee).toFixed(2)} nAVAX.`)
}
main()
getGas function calculates the total fee required to process a transaction. The function takes in a priorityFee as input representing the fee a user is willing to pay to prioritize their transaction processing. The function first converts the priorityFee from Gwei to Wei (the smallest unit of ether) using ethers.parseUnits. Then, it uses provider.getFeeData and reads the gasPrice field to retrieve the current base fee set by the network. The function finally adds the priority fee to the base fee and returns the total fee along with the base fee as an array.
The main function is the entry point of the code. It first sets a constant PRIORITY_FEE to 2 Gwei. Then calls the getGas function with PRIORITY_FEE as an argument and destructures the returned array into two variables totalFee and baseFee. The code then converts baseFee and totalFee from Wei to nAVAX using ethers.formatUnits for better readability, and logs the results to the console.
The main function logs the priority fee, the base fee at that moment, and the minimum recommended total fee that should be paid to process a transaction.Last modified on June 25, 2026
Was this page helpful?