Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getFeeHistory gives error when running local fork with hardhat #4510

Closed
1 task done
gndelia opened this issue Oct 29, 2021 · 5 comments · Fixed by #4529
Closed
1 task done

getFeeHistory gives error when running local fork with hardhat #4510

gndelia opened this issue Oct 29, 2021 · 5 comments · Fixed by #4529
Assignees
Labels
Bug Addressing a bug

Comments

@gndelia
Copy link

gndelia commented Oct 29, 2021

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

Not sure if this is an error in web3.js or in hardhat, but after reading some docs and tracing the possible bug fix I think it should be fixed here (I might be wrong!)

When calling getFeeHistory in my app, using a local fork with hardhat, I get the following error

Error: Internal JSON-RPC error.
{
  "code": -32602,
  "message": "Errors encountered in param 0: Invalid value 1 supplied to : QUANTITY"
}

Expected Behavior

I expect the proper response of eth_feeHistory, something like

{
        "oldestBlock": "0xce1806",
        "baseFeePerGas": [
            "0x26a51093d0",
            "0x2532e26b6d"
        ],
        "gasUsedRatio": [
            0.35032733868710536
        ]
    }

Steps to Reproduce

(according to the docs, these are valid parameters)

web3.eth.getFeeHistory('0x1', 'latest', []).then(console.log).catch(console.error)

By running this with a local fork with hardhat, I get the above-mentioned error (See below for hardhat config)

Web3.js Version

1.5.3

Environment

  • Operating System: Mac OS 11.6
  • Browser: Brave
  • Node.js Version: 14.16.1
  • NPM Version: 6.14.32

Anything Else?

hardhat config is pretty simple

.'use strict'
require('dotenv').config()

module.exports = {
  defaultNetwork: 'hardhat',
  networks: {
    hardhat: {
      accounts: {
        accountsBalance: '10000000000000000000000',
        mnemonic: process.env.MNEMONIC
      },
      forking: {
        url: process.env.BASE_NODE_URL,
        blockNumber: 8
      }
    },
    mainnet: {
      url: process.env.BASE_NODE_URL,
      chainId: 1
    }
  }
}

hardhat version: 2.6.7

so I just run npx hardhat node and connect with Metamask to that local fork

Then, the code of the app just do what I wrote in the "Steps to Reproduce" section
After a couple of hours of debugging; I found that if I change this line right here, updating the formatters for eth_feeHistory from

new Method({
  name: 'getFeeHistory',
  call: 'eth_feeHistory',
  params: 3,
  inputFormatter: [utils.toNumber, formatter.inputBlockNumberFormatter, null]
}),

to

new Method({
  name: 'getFeeHistory',
  call: 'eth_feeHistory',
  params: 3,
  // replace utils.toNumber here with utils.numberToHex
  inputFormatter: [utils.numberToHex, formatter.inputBlockNumberFormatter, null]
}),

then it works. I found this as part of implementing EIP-1559 for a dapp.

I tried to use this method with a fork with ganache-cli, but I also failed to make it work, but I am still unsure of the reasons, as the error was different.

Not sure if this is a problem in web3 or in hardhat though 😓

@gndelia gndelia added the Bug Addressing a bug label Oct 29, 2021
@luu-alex
Copy link
Contributor

Hey, sorry to hear you've been having issues with an RPC call.

I installed the same version of web3js and was able to sucessfully perform getFeeHistory, perhaps it is hardhat?

Web3.eth.getFeeHistory('0x1', 'latest', []).then(console.log).catch(console.error)
Promise { <pending> }
> {
  baseFeePerGas: [ '0x30aea7270d', '0x2deb22f72d' ],
  gasUsedRatio: [ 0.27291628440852755 ],
  oldestBlock: '0xce36b8'
}

If theres anything that points to web3js being an issue let us know and we'll try to investigate it when we can :)

@gndelia
Copy link
Author

gndelia commented Oct 30, 2021

Thanks for your response! I'll try to ping them on their side. I'm ok if you want to close this in the meantime. Thank you!

@fvictorio
Copy link

Hey @luu-alex, are you sure this isn't a problem in web3?

The eth_feeHistory section of the spec says that the first argument should be a hex-encoded unsigned string:

image

But here:

https://github.com/ChainSafe/web3.js/blob/3a3cb32b6434656131f0bfc4a8622130d19d2338/packages/web3-eth/src/index.js#L411

Web3 seems to be converting it to a plain number (as far as I understand, at least).

Some nodes might be more permissive in what they accept, which makes sense. But we try to follow the spec as much as possible, so that code that runs on Hardhat will run in any spec-compliant node.

@luu-alex luu-alex reopened this Nov 8, 2021
@luu-alex
Copy link
Contributor

luu-alex commented Nov 8, 2021

Hey @fvictorio thank you for taking a look, that makes alot of sense. I have reopened the issue and will try to tackle this problem. @gndelia I was curious are you still facing issues with a fork from ganache-cli? If so what was the error.

@luu-alex luu-alex self-assigned this Nov 8, 2021
@gndelia
Copy link
Author

gndelia commented Nov 8, 2021

I get Method eth_feeHistory not supported. - but that might be that I just need to update ganache-cli 😬

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Addressing a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants
@gndelia @fvictorio @luu-alex and others