eth_gasPrice | Fantom

Fantom 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.

👍

Get you own node endpoint today

Start 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 { Web3 } = require("web3");
const NODE_URL = "CHAINSTACK_NODE_URL";
const web3 = new Web3(NODE_URL);

async function getGasPrice() {
    const baseFee = await web3.eth.getGasPrice();
    const feeInGwei = web3.utils.fromWei(baseFee, "gwei")
    console.log(`The base gas fee is: ${baseFee} Wei`);
    console.log(`The base gas fee is: ${feeInGwei} Gwei`);
  }
  
  getGasPrice()
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 use eth_gasPrice to calculate the total gas value to send with a transaction based on the base and priority fee system. Ethereum's London hard fork implemented This concept with EIP-1559.

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 comprises a base fee determined by the network's load and a priority fee added by the user.

📘

Note

The eth_gasPrice method returns the base fee.

Try the eth_gasPrice RPC method yourself

Language
Click Try It! to start a request and see the response here!