Skip to main content

getFeeHistory

Callable


  • Type parameters

    Parameters

    • web3Context: Web3Context<EthExecutionAPI, any>

      (Web3Context) Web3 configuration object that contains things such as the provider, request manager, wallet, etc.

    • blockCount: Numbers

      Number of blocks in the requested range. Between 1 and 1024 blocks can be requested in a single query. Less than requested may be returned if not all blocks are available.

    • newestBlock: BlockNumberOrTag = web3Context.defaultBlock

      Highest number block of the requested range.

    • rewardPercentiles: Numbers[]

      A monotonically increasing list of percentile values to sample from each block’s effective priority fees per gas in ascending order, weighted by gas used. Example: [“0”, “25”, “50”, “75”, “100”] or [“0”, “0.5”, “1”, “1.5”, “3”, “80”]

    • returnFormat: ReturnFormat

      (DataFormat defaults to DEFAULT_RETURN_FORMAT) - Specifies how the return data from the call should be formatted.

    Returns Promise<{ baseFeePerGas: NumberTypes[ReturnFormat[number]]; gasUsedRatio: NumberTypes[ReturnFormat[number]][]; oldestBlock: NumberTypes[ReturnFormat[number]]; reward: NumberTypes[ReturnFormat[number]][][] }>

    baseFeePerGas and transaction effective priorityFeePerGas history for the requested block range if available. The range between headBlock - 4 and headBlock is guaranteed to be available while retrieving data from the pending block and older history are optional to support. For pre-EIP-1559 blocks the gasPrices are returned as rewards and zeroes are returned for the baseFeePerGas.

    web3.eth.getFeeHistory(4, 'pending', [0, 25, 75, 100]).then(console.log);
    > {
    baseFeePerGas: [
    22983878621n,
    21417903463n,
    19989260230n,
    17770954829n,
    18850641304n
    ],
    gasUsedRatio: [
    0.22746546666666667,
    0.2331871,
    0.05610054885262125,
    0.7430227268212117
    ],
    oldestBlock: 15216343n,
    reward: [
    [ '0x3b9aca00', '0x53724e00', '0x77359400', '0x1d92c03423' ],
    [ '0x3b9aca00', '0x3b9aca00', '0x3b9aca00', '0xee6b2800' ],
    [ '0x3b9aca00', '0x4f86a721', '0x77d9743a', '0x9502f900' ],
    [ '0xcc8ff9e', '0x53724e00', '0x77359400', '0x1ec9771bb3' ]
    ]
    }

    web3.eth.getFeeHistory(4, BlockTags.LATEST, [0, 25, 75, 100], { number: FMT_NUMBER.NUMBER , bytes: FMT_BYTES.HEX }).then(console.log);
    > {
    baseFeePerGas: [
    22983878621,
    21417903463,
    19989260230,
    17770954829,
    18850641304
    ],
    gasUsedRatio: [
    0.22746546666666667,
    0.2331871,
    0.05610054885262125,
    0.7430227268212117
    ],
    oldestBlock: 15216343,
    reward: [
    [ '0x3b9aca00', '0x53724e00', '0x77359400', '0x1d92c03423' ],
    [ '0x3b9aca00', '0x3b9aca00', '0x3b9aca00', '0xee6b2800' ],
    [ '0x3b9aca00', '0x4f86a721', '0x77d9743a', '0x9502f900' ],
    [ '0xcc8ff9e', '0x53724e00', '0x77359400', '0x1ec9771bb3' ]
    ]
    }