Skip to content

Latest commit

 

History

History
93 lines (67 loc) · 2.26 KB

basefeepercentile.md

File metadata and controls

93 lines (67 loc) · 2.26 KB
description
Get the base fee percentile for a chain.

import Tabs from "@theme/Tabs"; import TabItem from "@theme/TabItem";

Get the base fee percentile

Returns the base fee percentile (50th percentile) of the specified blockchain network.

For example, if the API returns a value of 20 Gwei, it means that 50% of the historical base fees are less than or equal to 20 Gwei.

This can be useful for users or applications to estimate the optimal gas price for transactions based on historical data.

GET https://gas.api.infura.io/networks/${chainId}/baseFeePercentile

Parameters

Path:

  • chainId: string - ID of the chain to query.

Returns

baseFeePercentile: string - The base fee in Gwei at the 50th percentile, meaning that 50% of the base fees are less than or equal to the provided amount.

Example

Request

Include your API key and optional API key secret to authorize your account to use the APIs.

:::tip You can call the API with only an API key, and include it as a path parameter instead of using the curl authentication option (-u). :::

curl -X "GET" \
  -u <YOUR-API-KEY>:<YOUR-API-KEY-SECRET> \
  "https://gas.api.infura.io/networks/1/baseFeeHistory"
const axios = require("axios");

const apiKey = "<YOUR-API-KEY>"; // Replace with your API key.
const apiKeySecret = "<YOUR-API-KEY-SECRET>"; // Replace with your API key secret.

const Auth = Buffer.from(apiKey + ":" + apiKeySecret).toString("base64");

// The chain ID of the supported network.
const chainId = 1;

(async () => {
  try {
    const { data } = await axios.get(
      `https://gas.api.infura.io/networks/${chainId}/baseFeePercentile`,
      {
        headers: {
          Authorization: `Basic ${Auth}`,
        },
      }
    );
    console.log("Base fee history:", data);
  } catch (error) {
    console.log("Server responded with:", error);
  }
})();

Response

{
  "baseFeePercentile": "23.227829059"
}