1

I previously used the getFeeHistory method with web3js version 1.x.x to obtain priority gas prices. After updating to versions 3.x.x or 4.x.x, I noticed this method is no longer available, with only getGasPrice being present. I attempted to construct a new method using web3-core, but it appears there's no built-in method to accomplish this task.

  1. How can the priority gas price be retrieved from the blockchain using these newer versions of web3?
  2. Why was the getFeeHistory method removed, and are there any recommended alternatives to achieve the same functionality without simulating a transaction?

1 Answer 1

0

You can retrieve the fee history using the eth_feeHistory JSON-RPC method in web3.js, even if there isn't a wrapper function for this request built into the library for versions 3 or 4. Here's how you can make this custom request:

const Web3 = require('web3');
const web3 = new Web3('YOUR_PROVIDER_URL');

web3.currentProvider.send(
  {
    jsonrpc: '2.0',
    method: 'eth_feeHistory',
    params: [blockCount, newestBlock, rewardPercentiles],
    id: new Date().getTime()
  },
  (error, result) => {
    if (error) {
      console.error(error);
    } else {
      console.log(result);
    }
  }
);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.